?
Solved

How can I delete printers via login script?

Posted on 2009-07-14
23
Medium Priority
?
643 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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 1000 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 1000 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Learn about cloud computing and its benefits for small business owners.
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…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Suggested Courses

765 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