Determining what default printer is in VBS/WSH
I'm trying to map each user's printers to a new print server with their login script in WSH.
I have the code (below) to successfully do this. However, the ONLY thing missing is setting the default printer. I know that there is a method that DOES set the default printer, but I first need to know what their old default printer was. I haven't been able to find this. I found (in other wrox forums) code in
VB that will use API calls to do this--but
AFAIK these won't work from WSH.
The code I have (slightly sloppy, I know, but it works) is this:
Code:
oldPrinter="\\PRSRV1\Color4002"
newPrinter="\\PRSRV2\Color4002"
For i = 0 to oPrinters.Count - 1 Step 2
if Trim(oPrinters.Item(i+1)) = oldPrinter then
'Printer found. Lets add the replacement, if successful delete the old.
WshNetwork.AddWindowsPrinterConnection newPrinter
If Err 0 OR blnError = True Then
'Printer was NOT added
Else
WshNetwork.RemovePrinterConnection oldPrinter, true, true
End If 'end if err0
End If 'end if printer matches current
Next
'END ITERATION SEARCHING FOR PRINTER
I do this for each printer we have on our network. I don't worry about specifying drivers, as I made a point to use the same driver version on both servers (for anyone copying, this may create an issue if the new print server has a different driver and the user it is being added from does not have local administrative rights). Each user has 5-10 printers that are actually remapped.
Any help on this? Thanks
-Dane