[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 714
  • Last Modified:

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 Davis
Robert Davis
  • 5
  • 4
1 Solution
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...
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Robert DavisAuthor Commented:
Mapping (printer UNC)

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

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_20680258.html 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...

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 http://www.experts-exchange.com/Programming/Misc/Q_20857609.html might be useful.

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now