hi,everyone
i write two wsf file, one to protect a word document and another to
unprotect it
code of protect one:
<job id="protect_word">
<script language="VBScript">
Option Explicit
Dim docPath, errorFile
docPath = WScript.Arguments(0)
errorFile = WScript.Arguments(1)
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
Dim errTextFile
Set errTextFile = fs.CreateTextFile(errorFile, True)
Dim wordApp, document
Set wordApp = CreateObject("Word.Application")
wordApp.DisplayAlerts = True
Set document = wordApp.Documents.Open(docPath)
Dim password
password="123"
document.Protect 0, False, password, False, False
If Err.Number = 0 Then
document.Save
Else
errTextFile.WriteLine("error information: " &
Err.Description)
End If
errTextFile.Close()
document.Close False
Set document = Nothing
wordApp.Quit
Set wordApp = Nothing
WScript.Quit(Err.Number)
</script>
</job>
code of unprotect one:
<job id="unprotect_word">
<script language="VBScript">
Option Explicit
Dim docPath, errorFile
docPath = WScript.Arguments(0)
errorFile = WScript.Arguments(1)
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
Dim errTextFile
Set errTextFile = fs.CreateTextFile(errorFile, True)
Dim wordApp, document
Set wordApp = CreateObject("Word.Application")
wordApp.DisplayAlerts = True
Set document = wordApp.Documents.Open(docPath)
Dim password
password="123"
If document.ProtectionType <> -1 Then
document.Unprotect password
End If
If Err.Number = 0 Then
document.Save
Else
errTextFile.WriteLine("发生错误, 错误信息: " & Err.Description)
End If
errTextFile.Close()
document.Close False
Set document = Nothing
wordApp.Quit
Set wordApp = Nothing
WScript.Quit(Err.Number)
</script>
</job>
but when i use the second to unprotect the word document, there is a
error: password is incorrect
i google it, and i didn't find the solution
Any help would be greatly appreciated.
thanks
zhi
Replies