我有一个感染了病毒的硬盘。 该病毒encryption文件,然后要求赎金解密他们。 这些文件是HELP_DECRYPT.HTML,HELP_DECRYPT.PNG,HELP_DECRYPT.TXT和HELP_DECRYPT.URL。
驱动器上有成千上万的受感染文件。 我试图写一个脚本来通过驱动器上的所有文件夹,如果它发现任何恶意文件,它会删除它们。 然后,我想要如果复制文件从备份驱动器在同一目录即。 如果在I \ Folder \中find,将从F \ Folder \中获取文件。
在我的情况下,受感染的驱动器是Y,而备份驱动器是X.
我是VBScripts相对较新,这是我到目前为止:
set fso = CreateObject("Scripting.FileSystemObject") ShowSubFolders FSO.GetFolder("Y:\"), 3 Sub ShowSubFolders(Folder, Depth) If Depth > 0 then For Each Subfolder in Folder.SubFolders 'Wscript.Echo Subfolder.Path DeleteFiles(subFolder.path) On Error Resume Next ShowSubFolders Subfolder, Depth -1 Next End if End Sub 'deletes the malicious files and calls the copy function' Function DeleteFiles(path) 'wscript.echo("in delete method") set FSO2 = Createobject("Scripting.FileSystemObject") set ofolder = createobject("Scripting.FileSystemObject") set ofolder = FSO2.GetFolder(path) if FSO2.FileExists("HELP_DECRYPT.URL") Then ofolder.DeleteFile("HELP_DECRYPT.PNG") ofolder.DeleteFile("HELP_DECRYPT.HTML") ofolder.DeleteFile("HELP_DECRYPT.URL") ofolder.DeleteFile("HELP_DECRYPT.TXT") wscript.echo("DeletedFiles") copyFiles(FSO.GetParentFolder) end if End Function 'copies files from the backup' Function CopyFiles(from) dim to1 'where we're copying to to1=from 'where we're copying from Call Replace (from, "Y:", "X:") SET FSO3 = CreateObject("Scripting.FileSystemObject") For Each file In from 'not sure about "file" FSO3 = file Call FSO3.CopyFile (from, to1, true)'copies file and overwrites if already there Next End Function
这是我会用的:
Option Explicit Dim FSO, badFiles Set FSO = CreateObject("Scripting.FileSystemObject") badFiles = Array("HELP_DECRYPT.PNG", "HELP_DECRYPT.URL", "HELP_DECRYPT.HTML", "HELP_DECRYPT.TXT") Walk FSO.GetFolder("Y:\") Sub Walk(folder) Dim subFolder For Each subFolder in folder.SubFolders DeleteFiles subFolder, badFiles RestoreFiles "X:", subFolder Walk subFolder Next End Sub Sub DeleteFiles(folder, filesToDelete) Dim file For Each file In filesToDelete file = FSO.BuildPath(folder.Path, file) If FSO.FileExists(file) Then FSO.DeleteFile file, True Next End Sub Sub RestoreFiles(sourceRoot, destinationFolder) Dim sourcePath, file WScript.Echo "Restoring " & destinationFolder.Path & " ..." sourcePath = Replace(destinationFolder.Path, destinationFolder.Drive, sourceRoot) If FSO.FolderExists(sourcePath) Then For Each file In FSO.GetFolder(sourcePath).Files WScript.Echo file.Name ' maybe add a DateLastModified check here? file.Copy FSO.BuildPath(destinationFolder.Path, file.Name), True Next Else WScript.Echo "Warning! Folder not found: " & sourcePath End If End Sub
使用VBScript的一般提示:
Option Explicit
On Error Resume Next
避免On Error Resume Next
。 简单地压制任何错误从来都不是一个好主意。 cscript.exe
在命令行上运行上面的脚本,这样您就可以看到脚本的Echo
输出,而不必点击1000年的消息框。 DeleteFiles()
RestoreFiles()
实际上不是根据当前的问题量身定制的。 您可能可以在不用更改脚本的情况下在不同的脚本中重新使用这些功能。