Startup Add Printer Script doesn't work on XP but does on 2000.

We use the following script at computer startup to map each rooms network printer to the computers in their room OU.  This works great for windows 2000, however in XP the scripts fails to work at startup.  Additionally, if the script is run from the SYSVOL share or if you copy the script locally and run it once logged in, the script runs fine on xp and maps the appropriate printer.  So what the heck is up XP?

Also we have the script following it run at shutdown to remove all printers, and while it works when run manually, it does not work at shutdown for 2000 or xp.

Additional information: 1 DC running Widnows 2000, AD & Printer Server.  Any help would be greatly appreciated.  Thanks!
rundll32 printui.dll,PrintUIEntry /in /q /n\\dc1\roomnumber-00p
rundll32 printui.dll,PrintUIEntry /y /q /n\\dc1\roomnumber-00p
Option Explicit
on error resume next
Dim oWSHNetwork, oPrinters, intCounter
'-- Setting objects --
Set oWshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = oWshNetwork.EnumPrinterConnections
For intCounter =1 to oPrinters.Count -1 Step 2
If Left (oPrinters(intCounter),2) = "\\" Then
          oWSHNetwork.RemovePrinterConnection oPrinters.Item(intCounter), true, true
     End If
'wscript.echo oPrinters.Item(intCounter)
'Clean up and exit the script
Set oWSHNetwork = Nothing
Set oPrinters = Nothing

Open in new window

Robert DavisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Printer connections are generall assigned per user - not per computer.
Run this script as a logon (user) script -not a startup (machine) script.
Robert DavisAuthor Commented:
The problem is this is a school and kids will merely click cancel on the pop-up that comes up during the printer mapping and not be able to print.  I'm trying to fool proof the system a little bit for the sake of the user.  Any other suggestions?
What popup do you get? The scripts should be hidden...
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Robert DavisAuthor Commented:
Mapping (printer UNC)

This is for startup and login, the chances of someone hittign cancel during startup is dramatically less though.

and235100Commented: might be useful.
Personally, I don't see this box - but if your network link is slow - then that might be why the users get  chance to cancel the mapping - there doesn't seem to be a way of hiding all messages.

@echo off
set pserver=<server name>
echo Remove All Network Printers.......
con2prt /f
echo Show All Available Printers From %pserver%.......
net view %pserver%
set /p pname= Enter Printer Name:
rundll32 printui.dll,PrintUIEntry /in /n\\%pserver%\%pname% /q
set pserver=
set pname=
Robert DavisAuthor Commented:
It's not a slow link and we don't have con2prt :-\.
How about a vbscript?

Set WshNetwork = CreateObject("WScript.Network")

WshNetwork.AddWindowsPrinterConnection "\\dc1\roomnumber-00p"
WshNetwork.SetDefaultPrinter "\\dc1\roomnumber-00p"

This should run - and not prompt anything.


Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection "\\dc1\roomnumber-00p"

The difference is - that the following vbscript works on XP:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = TRUE")

For Each objPrinter in colInstalledPrinters

But - it doesn't work on 2000 - the manual removal is the only way...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Robert DavisAuthor Commented:
Well the logon script works great, now for a removal script that works for 2000....

and235100: Why do you believe there is no way to remove a printer via script in 2000; right clicking and selecting delete must execute some sort of code...

Thank you - apologies for not getting back to you sooner.
I don't know what I said to give you the impression this wasn't possible, but might be useful.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server OS

From novice to tech pro — start learning today.