我忘记了打开Word文档的密码。如何检索密码?

时间:2015-06-10 09:33:46

标签: vba ms-word passwords password-recovery

我有一个word文档,提示用户输入密码,对话框如下所示。

"Enter Password to open file" 

我发现了一些使用暴力破解密码的代码(使用Excel编写)。唯一的问题是当我使用Documents.Open时,如果密码错误,则显示对话框 - 无论如何都要绕过这个?

Private Sub PasswordBreakerWord()
'Author unknown but submitted by brettdj of www.experts-exchange.com


Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim strPath As String
Dim passAtmp As String

strPath = "H:\My_Path\"

Set objWord = CreateObject("word.Application")
objWord.Visible = True

Dim i As Integer, j As Integer, k As Integer
Dim l As Integer, m As Integer, n As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer
On Error Resume Next
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126

  passAtmp = Chr(i) & Chr(j) & Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)

 On Error Resume Next
  Set objDoc = objWord.Documents.Open(Filename:=strPath & "High Yield FMA Procedures.doc", PasswordTemplate:=passAtmp)
 If Err <> 0 Then
    On Error GoTo 0
 Else
    MsgBox "password is: " & passAtmp
    Debug.Print passAtmp
    Exit Sub
End If

Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next

Set objWord = Nothing

End Sub

4 个答案:

答案 0 :(得分:4)

该文件必须采用.docx格式,如果.doc将其转换为.docx

  1. 创建文件的备份副本。
  2. 将扩展程序从.docx更改为.zip
  3. 打开新的.zip文件并提取所有文件。
  4. 在解压缩的文件夹中,转到word\settings.xml
  5. 打开settings.xml并将代码从<w:documentProtection移至/>并保存该文件。
  6. 将新settings.xml复制到原始.zip文件并覆盖旧文件。
  7. .zip重命名为.docx并打开现在无保护的文件!

答案 1 :(得分:1)

在尝试打开文件之前立即使用func hasJailbreak() -> Bool { #if arch(i386) || arch(x86_64) println("Simulator") return false #else var fileManager = NSFileManager.defaultManager() if(fileManager.fileExistsAtPath("/private/var/lib/apt")) { println("Jailbroken Device") return true } else { println("Clean Device") return false } #endif }

答案 2 :(得分:0)

As&#34; Matt&#34;说只需将文件扩展名转换为.zip,然后使用记事本或记事本++编辑.xml文件,在w:documentprotection之后将所有行删除到/&gt;然后在.zip文件夹中重新保存新的.xml文件将删除密码保护。在Word 2016中试过并测试过。只是不要忘记将现在编辑过的zip文件夹重命名为.docx,以便在Word中可读。全部归功于马特。

答案 3 :(得分:0)

我调整了您的原始代码,因此它并不取决于密码是否一定长度。现在它还将从左向右移动,每次通过都会添加一个新字符,并在尝试打开文档时防止弹出窗口。这也可以用于工作簿。

警告**蛮力方法甚至根本不值得。运行需要很长时间。如果它是加密密码,那么这可能是最好的选择,而无需下载第三方密码破解程序。

Sub PasswordBreakerWord()
Dim WordApp As Object
Dim WordDoc As Object
Dim strPath As String
Dim passAtmp As String

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Set WordApp = CreateObject("Word.Application")
Set WordDoc = CreateObject("Word.Document")
strPath = Environ("USERPROFILE") & "\Desktop\blah.docx"

Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer
Dim i7 As Integer, i8 As Integer, i9 As Integer
Dim i10 As Integer, i11 As Integer, i12 As Integer

For i1 = 31 To 126: For i2 = 31 To 126: For i3 = 31 To 126
For i4 = 31 To 126: For i5 = 31 To 126: For i6 = 31 To 126
For i7 = 31 To 126: For i8 = 31 To 126: For i9 = 31 To 126
For i10 = 31 To 126: For i11 = 31 To 126: For i12 = 31 To 126

passAtmp = Chr(i12) & Chr(i11) & Chr(i10) & Chr(i9) & Chr(i8) & Chr(i7) & Chr(i6) & Chr(i5) & Chr(i4) & Chr(i3) & Chr(i2) & Chr(i1)
Debug.Print passAtmp

On Error Resume Next
Set WordDoc = WordApp.Documents.Open(strPath, , True, , passAtmp)
If Err <> 0 Then
    On Error GoTo 0
Else
    MsgBox "password is: " & passAtmp
    Debug.Print passAtmp
    WordApp.Quit
    Application.DisplayAlerts = True
    Application.ScreenUpdating = False
    Exit Sub
End If

Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next

End Sub