Solved

How can I delete printers via login script?

Posted on 2009-07-14
23
636 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 M
ID: 24852396
Do you want to delete all printers or specific printers ?
0
 
LVL 25

Expert Comment

by:Ron M
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
 

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 M
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 M
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 M
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 M
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 25

Expert Comment

by:Ron M
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 M 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now