本帖最后由 RandomOS 于 2010.6.22 13:33 编辑
做潜水党好长时间了,在卡饭向许多高手学到了很多东西,现在也发点自己写的东西吧。没什么技术含量的东西,大家别见笑。
之前去打印店回来的时候,每次U盘里都有一大堆病毒(以文件夹病毒为主),虽然清除也很简单,但每次都要删除病毒文件并恢复隐藏的文件夹,也是蛮烦人的,所以就写了个自动清除的脚本。
- 'Code by RandomOS 2010-03-26
- On Error Resume Next
- Dim Udisks, VirusList, IsDelete
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set f = fso.GetFile(WScript.ScriptFullName)
- Set Disks = fso.Drives
- For Each Disk In Disks
- If Disk.IsReady And Disk.DriveType = 1 Then
- Udisks = Udisks &","&Disk.DriveLetter
- End If
- Next
- If Udisks = "" Then
- Msgbox "没有检测到U盘!",64,"提示"
- Wscript.Quit
- End If
- Udisks = Right(Udisks,len(Udisks)-1)
- UPan = Split(Udisks, ",")
- For Each U In UPan
- FindVirus(U&":")
- Next
- ClrWorm()
- If VirusList = "" Then
- Msgbox "未发现可疑文件!",64,"提示"
- Else
- IsDelete = Msgbox("发现以下可疑文件,是否删除?"& vbCrLf & VirusList , 4)
- If IsDelete = 6 Then
- ClrVirus()
- AntiAutoRun()
- Msgbox "可疑文件已删除!",64,"提示"
- ElseIf IsDelete = 7 Then
- Msgbox "您点了否!",64,"提示"
- End If
- End If
- SafeOpen()
- Sub FindVirus(Path)
- Set Folder = fso.GetFolder(Path) '查找根目录下的隐藏文件
- For Each f1 In Folder.Files '隐藏文件 32+2 ————— 32+1+2+4
- If (f1.Attributes > 1 And f1.Attributes < 8) Or (f1.Attributes > 33 And f1.Attributes < 40) Then
- VirusList = VirusList & Path & f1.name & vbCrLf
- ElseIf LCase(f1.name) = "autorun.inf" Then
- VirusList = VirusList & Path & f1.name & vbCrLf
- ElseIf LCase(f1.name) = "system.dll" Then
- VirusList = VirusList & Path & f1.name & vbCrLf
- End If
- Next
- For Each f1 In Folder.SubFolders '查找文件夹病毒
- If (fso.FileExists(Path&f1.name&".exe")) Then
- VirusList = VirusList & Path & f1.name&".exe" & vbCrLf
- ElseIf (fso.FileExists(Path&f1.name&".lnk")) Then
- VirusList = VirusList & Path & f1.name&".lnk" & vbCrLf
- ElseIf (fso.FileExists(Path&f1.name&".scr")) Then
- VirusList = VirusList & Path & f1.name&".scr" & vbCrLf
- ElseIf (fso.FileExists(Path&f1.name&".com")) Then
- VirusList = VirusList & Path & f1.name&".com" & vbCrLf
- End If
- Next
- VirusName = Split(VirusList, vbCrLf)
- VirusList = ""
- For i = 0 To Ubound(VirusName)-1 '去重
- For j = i+1 To Ubound(VirusName)
- If VirusName(i) = VirusName(j) Then
- VirusName(i) = ""
- Exit For
- End If
- Next
- If VirusName(i) <> "" Then
- VirusList = VirusList & VirusName(i) & vbCrLf
- End If
- Next
- End Sub
- Sub ClrVirus()
- VirusList = Left(VirusList, Len(VirusList)-2)
- VirusName = Split(VirusList, vbCrLf)
- '删除可疑文件
- For Each Virus In VirusName
- If fso.FileExists(Virus) Then
- fso.DeleteFile Virus, true
- End If
- Next
- '恢复文件夹属性
- For Each Virus In VirusName
- FolderPath = Left(Virus,Len(Virus)-4)
- If fso.FolderExists(FolderPath) Then
- Set f = fso.GetFolder(FolderPath)
- f.attributes = 16
- End If
- Next
- End Sub
- Sub ClrWorm()
- For Each U In UPan
- If fso.FolderExists(U &":\RECYCLER") Then
- fso.DeleteFolder U &":\RECYCLER", true
- End If
- Next
- End Sub
- Sub AntiAutoRun()
- For Each U In UPan
- If fso.FolderExists(U&":\Autorun.inf") = false Then
- fso.CreateFolder(U&":\Autorun.inf")
- Set f = fso.GetFolder(U&":\Autorun.inf")
- f.Attributes = 23
- End If
- If fso.FolderExists(U&":\system.dll") = false Then
- fso.CreateFolder(U&":\system.dll")
- Set f = fso.GetFolder(U&":\system.dll")
- f.Attributes = 23
- End If
- Next
- End Sub
- Sub SafeOpen()
- Set ws = CreateObject("Wscript.Shell")
- For Each U In UPan
- ws.Run U &":"
- Next
- End Sub
复制代码
复制以上代码,另存为“文件名.vbs ” 即可。或者直接下载我上传的附件。
每次插入U盘后,双击这个VBS,即可检测U盘下有没有文件夹病毒,按提示操作即可,最后脚本还会安全的打开你的U盘。如果嫌VBS的图标不好看的话,可以将其发送到桌面快捷方式,改一下图标。
U盘病毒检测.rar
(1.22 KB, 下载次数: 379)
|