Solved

How can I delete printers via login script?

Posted on 2009-07-14
23
641 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
NCR Printer 7156 1 45
Need printer help HP 1310 PSC series 12 63
AD account Auto logoff 1 39
Does this have a 'web interface'? 4 14
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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