明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1432|回复: 1

[资源] 检查U盘自动删除当前打开U盘内cad病毒

[复制链接]
发表于 2011-2-8 11:42 | 显示全部楼层 |阅读模式
在论坛上看到查杀cad病毒的程序多为手动查杀,现写了个自动删除的!!



  1.     Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer
  2.     Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Integer
  3.     Private Declare Function GetForegroundWindow Lib "user32" () As Integer

  4.     Public Const WM_DEVICECHANGE = &H219
  5.     Public Const DBT_DEVICEARRIVAL = &H8000
  6.     Public Const DBT_DEVICEREMOVECOMPLETE = &H8004
  7.     Dim DriveLetter As String

  8.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
  9.         If m.Msg = WM_DEVICECHANGE Then
  10.             Select Case m.WParam
  11.                 Case DBT_DEVICEARRIVAL
  12.                     Dim s() As DriveInfo = DriveInfo.GetDrives
  13.                     For Each drive As DriveInfo In s
  14.                         If drive.DriveType = DriveType.Removable Then
  15.                             DriveLetter = drive.Name.ToString()
  16.                             Timer1.Enabled = True
  17.                         End If
  18.                     Next
  19.                 Case DBT_DEVICEREMOVECOMPLETE
  20.                     Dim s() As DriveInfo = DriveInfo.GetDrives
  21.                     For Each drive As DriveInfo In s
  22.                         If drive.ToString = DriveLetter Then Exit Sub
  23.                     Next
  24.                     Timer1.Enabled = False
  25.             End Select
  26.         End If
  27.         MyBase.WndProc(m)
  28.     End Sub

  29.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  30.         Dim hdl As New IntPtr(GetForegroundWindow)
  31.         Dim strTitle As String = Space(GetWindowTextLength(hdl) + 1)
  32.         GetWindowText(hdl, strTitle, strTitle.Length)
  33.         If Left(strTitle, 3) = DriveLetter Then
  34.             File.Delete(strTitle& "\ACAD.LSP")
  35.         End If
  36.     End Sub



上面是一个简单的例子,可以根据需要自己修改,我觉得用做成服务最好。
发表于 2011-2-8 21:02 | 显示全部楼层
多谢楼主分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-18 22:20 , Processed in 0.182040 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表