bitwizard2
Programmer
Here's the deal. Our office has a computer that needs to switch back and forth between a local card printer (makes ID cards) and a network laser printer. The card printer is physically attached to LPT1. And because the computer uses an old DOS program, the network printer has to be mapped to LPT1 when that DOS program tries to print. Hence, the need to switch... whichever printer is needed has to be at LPT1 and the other one has to be set to print to a file.
Manually this can be done by opening the Windows Printers folder by the following:
-Switching from card printer to network printer:
--Change card printer from LPT1 to "print to file".
--Capture Port LPT1 to the shared laser printer address
--Change laser printer from "print to file" to LPT1.
-Switching from network printer to card printer:
--Change laser printer from LPT1 to "print to file".
--End capture on LPT1
--Change card printer from "print to file" to LPT1.
Easy enough - so I thought I could write a windows script to make the change in one click.
Here's what I have:
***Start Code***
Set WshShell = WScript.CreateObject("WScript.Shell"
If WshShell.RegRead("HKLM\System\CurrentControlSet\Control\Print\Printers\Eltron P420 Card Printer\Port" = "FILE:" Then
'Switching to Card Printer
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\Eltron P420 Card Printer\Port", "LPT1:"
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\HP LaserJet 1100\Port", "FILE:"
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\Eltron P420 Card Printer\Attributes", &H51
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\HP LaserJet 1100\Attributes", &H41
WshShell.RegDelete "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\ProviderName"
WshShell.RegDelete "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\RemotePath"
WshShell.RegDelete "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\UserName"
WScript.Echo "Now set to print to the Card Printer."
Else
'Switching to Laser Printer
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\Eltron P420 Card Printer\Port", "FILE:"
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\HP LaserJet 1100\Port", "LPT1:"
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\Eltron P420 Card Printer\Attributes", &H41
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\HP LaserJet 1100\Attributes", &H51
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\", ProviderName, "REG_SZ"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\ProviderName", "Microsoft Network"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\", RemotePath, "REG_SZ"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\RemotePath", "\\BILLING\HP"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\", UserName, "REG_SZ"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\UserName", "OFFICE"
WScript.Echo "Now set to print to the Laser Printer."
End If
***End Code***
Problem is that when this code changes the attributes in the registry (the WshShell.RegWrite lines that end with &H51 or &H41) it changes the type, too. Windows keeps the attributes as a DWORD hex value and when I run the code it changes to a string. What's the fix to that?
Any help is much appreciated!
David
Manually this can be done by opening the Windows Printers folder by the following:
-Switching from card printer to network printer:
--Change card printer from LPT1 to "print to file".
--Capture Port LPT1 to the shared laser printer address
--Change laser printer from "print to file" to LPT1.
-Switching from network printer to card printer:
--Change laser printer from LPT1 to "print to file".
--End capture on LPT1
--Change card printer from "print to file" to LPT1.
Easy enough - so I thought I could write a windows script to make the change in one click.
Here's what I have:
***Start Code***
Set WshShell = WScript.CreateObject("WScript.Shell"
If WshShell.RegRead("HKLM\System\CurrentControlSet\Control\Print\Printers\Eltron P420 Card Printer\Port" = "FILE:" Then
'Switching to Card Printer
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\Eltron P420 Card Printer\Port", "LPT1:"
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\HP LaserJet 1100\Port", "FILE:"
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\Eltron P420 Card Printer\Attributes", &H51
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\HP LaserJet 1100\Attributes", &H41
WshShell.RegDelete "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\ProviderName"
WshShell.RegDelete "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\RemotePath"
WshShell.RegDelete "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\UserName"
WScript.Echo "Now set to print to the Card Printer."
Else
'Switching to Laser Printer
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\Eltron P420 Card Printer\Port", "FILE:"
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\HP LaserJet 1100\Port", "LPT1:"
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\Eltron P420 Card Printer\Attributes", &H41
WshShell.RegWrite "HKLM\System\CurrentControlSet\Control\Print\Printers\HP LaserJet 1100\Attributes", &H51
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\", ProviderName, "REG_SZ"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\ProviderName", "Microsoft Network"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\", RemotePath, "REG_SZ"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\RemotePath", "\\BILLING\HP"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\", UserName, "REG_SZ"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Network\Persistent\LPT1\UserName", "OFFICE"
WScript.Echo "Now set to print to the Laser Printer."
End If
***End Code***
Problem is that when this code changes the attributes in the registry (the WshShell.RegWrite lines that end with &H51 or &H41) it changes the type, too. Windows keeps the attributes as a DWORD hex value and when I run the code it changes to a string. What's the fix to that?
Any help is much appreciated!
David