讓你的電腦只識別你的優盤

來源:互聯網
上載者:User
     
     目前各種優盤病毒橫行,特別是我所在實驗室的電腦是會被別人使用的,對別人優盤上面的病毒十分煩惱,有一段時間我在CIMS參數裡面封掉了USB介面,然而啟動USB介面還需要重新啟動電腦,很麻煩。
     那麼如何用程式的方式關閉和啟動USB介面呢?如何讓你的電腦只使用你的優盤呢?
     如果感興趣,繼續看下去。
     1.在form1類裡面重載windows訊息接受函數,檢測優盤插入。 
     2.檢測優盤的認證資訊。    
     3.如果認證不是你的優盤,掉用windows外殼組件shell.dll。執行優盤的右擊菜單中的“彈出”。
     註:1.可以在你的優盤中放一個文字檔(txt,excel、ini、rtf、xml等)儲存密碼資訊,該密碼作為認證的憑證。
         2.通過shell.dll調用能執行windows系統中的幾乎所有的捷徑功能表(前面有文章已經給出了源碼),當然執行優盤格式化也是可以的,如果防止病毒傳染,檢測到優盤插入,直接格式化也不錯。

   主要源碼:
         1.檢驗隨身碟插入代碼
         const int DBT_DEVICEARRIVAL = 0x8000;
         const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
         protected override void WndProc(ref Message mess)
          {
            try
            {
                if (m.Msg == WM_DEVICECHANGE)
                {
                    switch (m.WParam.ToInt32())
                    {
                      case DBT_DEVICEARRIVAL://隨身碟插入
                            DriveInfo[] s = DriveInfo.GetDrives();
                            foreach (DriveInfo drive in s)
                            {
                                if ((drive.DriveType == DriveType.Removable)
                                                &&(drive.Name.ToString()=="A:\\"))
                                {
                                    //listBox1.Items.Add("隨身碟已插入,盤符為:"            
                                                             +drive.Name.ToString());
                                    //MessageBox.Show("優盤插入!盤符為:" + drive.Name.ToString
                                          (),"注意");
                                    tan_chu();
                                    break;
                                }
                            }
                            break;
                        case DBT_DEVICEREMOVECOMPLETE: //隨身碟卸載
                            //MessageBox.Show("優盤已經卸載。");
                            break;
                        default:
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            base.WndProc(ref mess);
        }
        2.彈出隨身碟代碼

        static private void tan_chu()
        {
            Shell32.Shell sh = new Shell32.Shell();
            Shell32.Folder sf = sh.NameSpace(17);//diann
            Shell32.FolderItems fis = sf.Items();

            while (true)
            {
                try
                {
                    for (int i = 0; i < fis.Count; i++)
                    {
                        string itemName = fis.Item(i).Name.ToString();
                        if (itemName == "可移動磁碟 (K:)")
                        {
                            Shell32.FolderItemVerbs fivs = fis.Item(i).Verbs();

                            foreach (Shell32.FolderItemVerb fv in fivs)
                            {
                                string name = fv.Name.ToString();
                                if (name == "彈出(&J)")
                                {
                                    fv.DoIt();
                                    // break;
                                }
                                //if (name == "掃描病毒(&K)")
                                //{
                                //    fv.DoIt();
                                //    // break;
                                //}
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    string exx = ex.Message.ToString();
                }
            }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.