1.

Solve : print record of minimized Word documents??

Answer»

Quote from: Sidewinder on NOVEMBER 08, 2010, 05:32:32 AM

The MRU is stored in the registry. Unfortunately it is stored as a sequence of null-terminated strings which I could not figure out how to represent in a batch file. This little snippet of VBScript code may help:

Code: [Select]' List the documents in the Word MRU registry key
'
Const HKEY_CURRENT_USER = &H80000001

strComputer = "."
strKeyPath = "Software\Microsoft\Office\11.0\Common\Open Find\Microsoft Word\Settings\Save As\File Name MRU"
strValueName = "Value"

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

oReg.GetMultiStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues

If Right(LCase(WScript.FullName), 11) = "cscript.exe" Then
For Each strValue In arrValues
WScript.Echo "Document - " & strValue
Next
Else
For Each strValue In arrValues
strBlock = strBlock & "Document - " & strValue & vbCrLf
Next
WScript.Echo strBlock
End If

Save the script with a VBS extension. It can be RUN from the command prompt as cscript scriptname.vbs or wscript scriptname.vbs If run with the former, output will be DIRECTED to the console as a list of documents. If run with the latter, outout will be a single window with all the documents listed. To produce a hardcopy, use cscript and redirect the output to your printer Ex: cscript scriptname.vbs > lpt1 .

Note: I'm still using Word XP (2002) so I got the Word 2003 registry key from the internet. With any luck it is correct. In any case, the registry is used only for reading, so there is no danger of mucking it up.

Good luck.


Uhmm this looks complex for me. Is there any simpler explanation? Thanks.
Wow! This is your lucky day. Today, and today only, explanations are just 5¢ and simpler explanations are just 7¢. As usual the script is free.

Quote
Const HKEY_CURRENT_USER = &H80000001

strComputer = "."
strKeyPath = "Software\Microsoft\Office\11.0\Common\Open Find\Microsoft Word\Settings\Save As\File Name MRU"
strValueName = "Value"

Assigns the registry key to various variables. The registry key is specific to Word 2003 and will be different for other versions. Also designates the local computer to do the processing.

Quote
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

oReg.GetMultiStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues

This is the heart of the script. Connects to the WMI class which contains the properties and methods needed to access the Windows registry. The MRU is a sequence of null-terminated strings, which the GetMultiStringValue returns as an array. Arrays are easy to process in VBScript, a registry sequence of null-terminated strings not so much.

Quote
If arrValues(0) = "" Then
WScript.Echo "MRU List Is Empty"
WScript.Quit
End If

If the MRU is empty, this error trap will allow for a gentle landing instead of the script CRASHING into the side of a mountain. Well maybe not so dramatic, but if you have an empty MRU you'll see the results from this code.

Quote
If Right(LCase(WScript.FullName), 11) = "cscript.exe" Then
For Each strValue In arrValues
WScript.Echo "Document - " & strValue
Next
Else
For Each strValue In arrValues
strBlock = strBlock & "Document - " & strValue & vbCrLf
Next
WScript.Echo strBlock
End If

This code formats the output returned in the array of MRU items. It queries which interpreter is being used (VBScript has two) and takes advantage of how the echo instruction works in each.

And there you have it. Please pay the cashier on your way out.

Good luck.


Discussion

No Comment Found