• 大小: 90KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-04
  • 语言: C#
  • 标签: C#  u盘  

资源简介

C# u盘操作源代码 识别插入u盘,拔出等

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace Upan
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public const int WM_DEVICECHANGE = 0x219;
        public const int DBT_DEVICEARRIVAL = 0x8000;
        public const int DBT_CONFIGCHANGECANCELED = 0x0019;
        public const int DBT_CONFIGCHANGED = 0x0018;
        public const int DBT_CUSTOMEVENT = 0x8006;
        public const int DBT_DEVICEQUERYREMOVE = 0x8001;
        public const int DBT_DEVICEQUERYREMOVEFAILED = 0x8002;
        public const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
        public const int DBT_DEVICEREMOVEPENDING = 0x8003;
        public const int DBT_DEVICETYPESPECIFIC = 0x8005;
        public const int DBT_DEVNODES_CHANGED = 0x0007;
        public const int DBT_QUERYCHANGECONFIG = 0x0017;
        public const int DBT_USERDEFINED = 0xFFFF;

        protected override void WndProc(ref Message m)
        {
            m = NewMethod(m);
            base.WndProc(ref m);

        }

        private Message NewMethod(Message m)
        {
            try
            {
                if (m.Msg == WM_DEVICECHANGE)
                {
                    switch (m.WParam.ToInt32())
                    {
                        case WM_DEVICECHANGE:
                            break;
                        case DBT_DEVICEARRIVAL://U盘插入
                            DriveInfo[] s = DriveInfo.GetDrives();
                            foreach (DriveInfo drive in s)
                            {
                                if (drive.Name.ToString() == “A:\\“)
                                {
                                    continue;
                                }
                                if (drive.DriveType == DriveType.Removable)
                                {
                                    listBox1.Items.Add(“U盘已插入,盘符为:“ + drive.Name.ToString());
                                    DialogResult dr=MessageBox.Show(“是否要拷贝U盘中的信息?““U盘“MessageBoxButtons.OKCancel);
                                    if (dr == DialogResult.OK)
                                        {
                                        SaveFileDialog Save = new SaveFileDialog();
                                        Save.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                                        Save.ValidateNames = true; //文件有效性验证ValidateNames,验证用户输入是否是一个有效的Windows文件名
                                        Save.RestoreDirectory = true;
                                          //Save.CheckPathExists = true; //验证文件有效性
                                        Save.Filter=@“所有文件|*.*\“; 
                            

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-11-17 13:27  Upan\
     目录           0  2015-11-17 13:27  Upan\Backup\
     目录           0  2015-11-17 13:27  Upan\Backup\Upan\
     文件        1194  2010-03-12 10:14  Upan\Backup\Upan.sln
     文件       17920  2010-03-25 17:22  Upan\Backup\Upan.v12.suo
     文件        6341  2010-03-12 12:52  Upan\Backup\Upan\Form1.cs
     文件        1945  2010-03-12 10:14  Upan\Backup\Upan\Form1.Designer.cs
     文件        5814  2010-03-12 10:14  Upan\Backup\Upan\Form1.resx
     文件         485  2010-03-12 09:29  Upan\Backup\Upan\Program.cs
     目录           0  2015-11-17 13:27  Upan\Backup\Upan\Properties\
     文件        1364  2010-03-12 09:29  Upan\Backup\Upan\Properties\AssemblyInfo.cs
     文件        2858  2010-03-12 09:29  Upan\Backup\Upan\Properties\Resources.Designer.cs
     文件        5612  2010-03-12 09:29  Upan\Backup\Upan\Properties\Resources.resx
     文件        1089  2010-03-12 09:29  Upan\Backup\Upan\Properties\Settings.Designer.cs
     文件         249  2010-03-12 09:29  Upan\Backup\Upan\Properties\Settings.settings
     文件        2018  2010-03-12 10:43  Upan\Backup\Upan\UClass.cs
     文件        3756  2010-03-12 10:43  Upan\Backup\Upan\Upan.csproj
     目录           0  2015-11-17 12:08  Upan\Setup1\
     目录           0  2010-03-12 13:50  Upan\Setup1\Debug\
     目录           0  2010-03-12 13:50  Upan\Setup1\Release\
     文件       25367  2010-03-12 10:14  Upan\Setup1\Setup1.vdproj
     目录           0  2015-11-17 12:08  Upan\Upan\
     文件        1273  2015-11-17 13:27  Upan\Upan.sln
     文件       17920  2010-03-25 17:22  Upan\Upan.suo
     文件       46592  2015-11-17 17:01  Upan\Upan.v12.suo
     目录           0  2015-11-17 12:08  Upan\Upan\bin\
     目录           0  2015-11-17 12:08  Upan\Upan\bin\Debug\
     文件       11264  2015-11-17 14:00  Upan\Upan\bin\Debug\Upan.exe
     文件       30208  2015-11-17 14:00  Upan\Upan\bin\Debug\Upan.pdb
     文件       21656  2015-11-17 16:32  Upan\Upan\bin\Debug\Upan.vshost.exe
     文件         490  2013-06-18 20:28  Upan\Upan\bin\Debug\Upan.vshost.exe.manifest
............此处省略27个文件信息

评论

共有 条评论