Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a lab area with about 75 XP boxes in it. At logon, we map two served printers with the AddWindowsPrinterConnection method in a VBS. 5-10% of the time, the users find that the printers have not mapped successfully and their print jobs fail. If they reboot or log out, the printers will usually map successfully on the second try.

I'd like to add logic to my script to check if the printers mapped properly, and if not, rerun the AddWindowsPrinterConnection command - but I don't know how to check programmatically if a printer object has been mapped.

Or is there a more reliable strategy for mapping multiple printers persistently for these profiles? Are logon scripts still the best way to do this?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Have a look at the script below. It reports on the print connections currently assigned. This should give you enough to get you started re: your own script, I would think.

OPTION EXPLICIT

Dim oNetwork    		' WScript.Network object
Dim colPrinters 		' A collection of the users printer connections
Dim x   			' The canonical scratch variable of doom!

On Error Resume Next

Set oNetwork = CreateObject("WScript.Network")
Set colPrinters = oNetwork.EnumPrinterConnections

' Iterate thru the collection of printers
for x = 1 to colPrinters.count Step 2
    WScript.Echo "Printer: '" & colPrinters(x) & "' on port '" & colPrinters(x - 1) & "'"
next

set oNetwork = Nothing
set oShell = Nothing
share|improve this answer
    
Thanks Evan! I'm not great at VBScript but this is definitely a good jumping-off point. I haven't really worked with arrays (collections?) much in VBS. I'll give this answer a pretty green checkmark if I can hack the rest of this out :) –  Doug Chase Oct 23 '09 at 12:48
    
Maybe I'll just say "If colPrinters.Count != 4 { try again }" –  Doug Chase Oct 23 '09 at 12:51
    
Turned out that for four mapped printer objects, colPrinters.Count == 8. It works pretty reliably to retry if the script finds that it isn't 8. So far I haven't seen the failure reoccur. –  Doug Chase Oct 23 '09 at 14:02
    
But I still feel like mapping these every time someone logs in is clunky. Isn't there a better way to do this? –  Doug Chase Oct 23 '09 at 14:18

You may want to also look at using the Printer Admin tool (prnadmin.dll) which comes as part of the Windows Resource Kit. It give a greater deal of control for what printers are on a particular system or in a user's profile.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.