Set and restore the default printer

I successfully followed the discussion http://forums.pdfforge.org/discussion/comment/8178#Comment_8178 to automatically send a mail with PDF attached.

I need a little more help with VBS, this is the task sequence:
- store the default printer in a text file (to do)
- change to PDFCreator (done)
- prepare and send mail (done)
- restore the default printer from the a.m. text file (to do)

I found some code on the web to read the default printer and store in a variable:

Dim strValue, strPrinter
Set oShell = CreateObject(“WScript.Shell”)
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
strPrinter = oShell.RegRead(strValue)
strPrinter = Split(strPrinter, “,”)(0)
WScript.Echo strPrinter

but I lose it when the script ends. This is why I need to store it in a file.

Any help is appreciated

I presume there is a way in the pdfcreator API, but I don’t know it well enough to help with it.  But you might do a google search for PrintUI.exe and command lines.  

Hello KWiK, thank you for your reply
I have "solved" creating (manually) a backup key in the register where I store the default printer and later reading that key to restore it.

code to read and store in backup:

Set oShell = CreateObject("WScript.Shell")
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
strPrinter = oShell.RegRead(strValue)
strPrinter = Split(strPrinter, ",")(0)
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\DeviceBackup"
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite strValue, strPrinter
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "PDFCreator"

code to restore from backup:
Set oShell = CreateObject("WScript.Shell")
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\DeviceBackup"
strPrinter = oShell.RegRead(strValue)
strPrinter = Split(strPrinter, ",")(0)
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter strPrinter