Solved

How can I delete printers via login script?

Posted on 2009-07-14
23
637 Views
Last Modified: 2012-05-07
I'm in need of deleting printer(s) via login script.  I know nothing of VBS and I've always used simple DOS commands to make things happen.  I've tried using net use \\servername\printername /delete but this doesn't work.  

Ideally what I'd like to do is delete all printers at the beginning of the script and install the ones I want.  Thanks in advance.
0
Comment
Question by:GTKINC
  • 9
  • 8
  • 5
  • +1
23 Comments
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 24852396
Do you want to delete all printers or specific printers ?
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 24852435
cscript "%systemroot%\system32\prnmngr.vbs" -x

That should delete all printers...
0
 
LVL 2

Expert Comment

by:opnj
ID: 24852445
rundll32 printui.dll,PrintUIEntry /gd /c\\machine /n\\machine\printer
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:GTKINC
ID: 24852577
I would like to delete all printers at the beginning of the script and install all printers needed.  I have this in the script for drive mappings but not for printers.  I'm not familiar with the sytax needed.
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 24852634
prnmngr.vbs is built in to windows for this purpose.....
'Delete All Printers
cscript "%systemroot%\system32\prnmngr.vbs" -x

'install printers...
cscript "%systemroot%\system32\prnmngr.vbs" -ac \\servername\printername
0
 

Author Comment

by:GTKINC
ID: 24852822
I placed cscript "%systemroot%\system32\prnmngr.vbs" -x and it said Input Error: Can not find script file "C:\windows\system32\prnmngr.vbs".  

This is a SBS 2K3 network with Vista workstations.
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 24852891
For Vista try just using "prnmngr.vbs" without the path...
I think it's actually located here:  \windows\system32\printing_admin-scripts\en-us\prnmngr.vbs
0
 

Author Comment

by:GTKINC
ID: 24853043
Sorry to not get it but I don't know what to change.  
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 24853114
Just take out the path to the script...

Try it like this:   cscript prnmngr.vbs -x
0
 

Author Comment

by:GTKINC
ID: 24853441
The first post (cscript "%systemroot%\system32\prnmngr.vbs" -x) works great on XP.  I'll try the other on a Vista box in a moment.  As for the deleting and the installation of printers, is there any advantage to using the vbs to install the printers?
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 24853496
There's not really an advantage per se..... except that the vbs file has more options for scripting drivers and port configurations.  That doesn't really apply to you if all of the printers are on a print server....  "net use" would do exactly the same thing for installing..
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 24853500
I think if you do this...
cscript prnmngr.vbs -x

instead of this...
cscript "%systemroot%\system32\prnmngr.vbs" -x
.....
It would work for both xp and vista...
0
 

Author Comment

by:GTKINC
ID: 24853515
The script deletes all of my local printers also.  I only need it to delete the network printers.  Can we do this?
0
 

Author Comment

by:GTKINC
ID: 24862006
What can I add or take away from the script so that all of my printers aren't deleted?  I only need to delete the network printers.
0
 
LVL 4

Expert Comment

by:pnrhait
ID: 24862067
to delete printer:

objNetwork.RemovePrinterConnection "\\server\sharename"

Add printer via security groups:

If IsAMemberOf
(objNetwork.UserDomain,objNetwork.UserName,"adsecuritygroupname") Then AddPrinterConnection "\\server\sharename"
0
 
LVL 4

Expert Comment

by:pnrhait
ID: 24862123
sorry forget to just add a network printer:

WshNetwork.AddWindowsPrinterConnection "\\server\sharename"

make sure to have the remove before the add
0
 
LVL 4

Expert Comment

by:pnrhait
ID: 24862142
could you please attach your script for me and I can modify it for you.
0
 
LVL 25

Accepted Solution

by:
Ron Malmstead earned 250 total points
ID: 24862208
This will delete networked printers...

rundll32 printui.dll,PrintUIEntry /gn /c\\targetmachine /n\\server\printershare



0
 

Author Comment

by:GTKINC
ID: 24862220
At present I don't have anything in my script other than one drive mapping and a printer to start.

net use * /delete /yes
net use x: \\servername\billing

rem cscript "%systemroot%\system32\prnmngr.vbs" -x
(this was the first script I had and it deletes all of my installed printers.)


start \\servername\P4014n
0
 

Author Comment

by:GTKINC
ID: 24862241
Do I have to name the specific printer in the script or can I set it to delete any network printers?  
0
 
LVL 4

Expert Comment

by:pnrhait
ID: 24862608
Give this a try.. it will map your X: you just need to add each printer unfortunately that you want to remove and add.. just put in you server name in each spot, and the printer sharename where it stats sharename
test.txt
0
 
LVL 4

Assisted Solution

by:pnrhait
pnrhait earned 250 total points
ID: 24862621
On Error Resume Next
Dim objFSO,objFILE,objShell,objNetwork,objProcessEnvironment,objOS,ActiveDHCPIPAddress
set objFSO=CreateObject("Scripting.FileSystemObject")
set objShell=CreateObject("Wscript.Shell")
set objNetwork=CreateObject("Wscript.Network")

'Map network drives

Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "X:","\\server\billings"

'remove network printers

objNetwork.RemovePrinterConnection "\\server\sharename"

'add network printers

WshNetwork.AddWindowsPrinterConnection "\\server\sharename"
0
 

Author Closing Comment

by:GTKINC
ID: 31603392
Thanks for your efforts.  Both solutions worked great for me.  
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question