-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWord unlocker.ps1
More file actions
62 lines (57 loc) · 2.04 KB
/
Word unlocker.ps1
File metadata and controls
62 lines (57 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#unlocks password protected word documents so they can be edited freely, just in case one needs to be edited.
#Created 6-19-2013
#mostly created this to save time and learn more about powershell.
if (!(Test-Path -path C:\TEMP\UNLOCK\)) {New-Item C:\TEMP\UNLOCK -Type Directory}
Remove-Item -recurse C:\TEMP\UNLOCK\*
function Select-FileDialog
{
param([string]$Title,[string]$Directory,[string]$Filter="All Files (*.*)|*.*")
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$objForm = New-Object System.Windows.Forms.OpenFileDialog
$objForm.InitialDirectory = $Directory
$objForm.Filter = $Filter
$objForm.Title = $Title
$Show = $objForm.ShowDialog()
If ($Show -eq "OK")
{
Return $objForm.FileName
}
Else
{
Write-Error "Operation cancelled by user."
}
}
$FILE = Select-FileDialog -Title "Select a locked word document" -Filter "Word Documents|*.docx"
$DEST = Copy-Item $FILE -destination C:\TEMP\ -PassThru
$FNAME = $DEST.Name
$NZIP = $FNAME -replace ".docx",".zip"
$ZIP = Rename-Item $DEST -NewName $NZIP -PassThru
$shell_app=new-object -com shell.application
$zip_file = $shell_app.namespace(($ZIP).FullName)
$destination = $shell_app.namespace("C:\TEMP\UNLOCK")
$destination.Copyhere($zip_file.items())
Remove-Item $ZIP.FullName
set-content $ZIP.FullName ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
$xml = New-Object xml
$xml.Load("C:\TEMP\UNLOCK\word\settings.xml")
$XML.settings.documentProtection|foreach {$_.Enforcement = '0'}
$xml.save("C:\TEMP\UNLOCK\word\settings.xml")
$zip_file.CopyHere("C:\TEMP\UNLOCK\Customxml")
sleep 1
$zip_file.CopyHere("C:\TEMP\UNLOCK\docProps")
sleep 1
$zip_file.CopyHere("C:\TEMP\UNLOCK\word")
sleep 2
$zip_file.CopyHere("C:\TEMP\UNLOCK\_rels")
sleep 1
$zip_file.CopyHere("C:\TEMP\UNLOCK\[Content_Types].XML")
sleep 1
$UDOCX = $ZIP.Name -replace ".zip","_UNLOCKED.docx"
$UFILE = Rename-Item $ZIP.FullName -newname $UDOCX -PassThru
Move-Item $UFILE.FullName -Destination (split-path $FILE)
Remove-Item -recurse C:\TEMP\UNLOCK\*
echo $FILE
echo $DEST
echo $FNAME
echo $NZIP
echo $ZIP.FullName