A post on a forum I visit frequently mobilized me to create a script to remove a password (the one required to open a file) from any number of Word files. Because nobody would want to open a 100 files and manually save them...
Of course, you have to know it. The following script doesn't do any cracking.
As you can see it's pretty straightforward and simple
- lines 1 to 3 declare three variables:
* Source Path
* Destination Path
- line 4 shows you the variable storing the password
- line 5 declares new COM object of the Word.Application type. It'll be used to process Word files. It's important to declare it here, not in the loop, as object creation requires some processing power.
- line 6 means something like that: "for each item called $file, matching the Get-ChildItem query, do the following...". The GCI query has been assigned to a variable so we can display item counter later.
- line 8 - this Property controls the visibility of the Word window.
- line 9 - we use the Documents.Open method with a couple of parameters:
* - full name of a file (base name + extension)
* - we don't care about document conversion window
* - we don't want the document to become Read Only
* - a password to open the file
* - a password to open the file - probably not required
- line 10 - activation of the object
- line 11 - setting the document password to NULL
- line 12 - writing the document to the specified path. Both variables are being joined to form a full path (it doesn't check for the backslash to separate a path from a file name, so you must provide it in the destination path)
- line 13 - closing of a file
- line 14 - message that uses the counter to let us know about the progress
- line 15 - counter incrementation
- line 17 - quits the Word application
As you can see is quite easy script. It isn't foolproof, the destination folder must exist too.
The main reason though is the way to remove the password in a batch. And I think it works great doing this.
But what's the language that this code is written for?
You should mention that the "Script is in what language?" and "how to be used!".
The commands don't seem familiar to me.
please edit it.
As seen in the Zone tag it's written in the PowerShell. I'll edit the article but essentially - you'll have to learn the basics from the MSDN.
I understood it after posting the comment!
When I run your code I get:
Exception setting "Open": Cannot convert the "xxx!" value of type "string" to type "Object".
where my password is "xxx!".
It says the same if I give "xxx!" as a literal parameter to Open