How can I delete printers via login script?

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.
GTKINCAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ron MalmsteadInformation Services ManagerCommented:
Do you want to delete all printers or specific printers ?
0
Ron MalmsteadInformation Services ManagerCommented:
cscript "%systemroot%\system32\prnmngr.vbs" -x

That should delete all printers...
0
opnjCommented:
rundll32 printui.dll,PrintUIEntry /gd /c\\machine /n\\machine\printer
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

GTKINCAuthor Commented:
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
Ron MalmsteadInformation Services ManagerCommented:
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
GTKINCAuthor Commented:
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
Ron MalmsteadInformation Services ManagerCommented:
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
GTKINCAuthor Commented:
Sorry to not get it but I don't know what to change.  
0
Ron MalmsteadInformation Services ManagerCommented:
Just take out the path to the script...

Try it like this:   cscript prnmngr.vbs -x
0
GTKINCAuthor Commented:
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
Ron MalmsteadInformation Services ManagerCommented:
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
Ron MalmsteadInformation Services ManagerCommented:
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
GTKINCAuthor Commented:
The script deletes all of my local printers also.  I only need it to delete the network printers.  Can we do this?
0
GTKINCAuthor Commented:
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
pnrhaitCommented:
to delete printer:

objNetwork.RemovePrinterConnection "\\server\sharename"

Add printer via security groups:

If IsAMemberOf
(objNetwork.UserDomain,objNetwork.UserName,"adsecuritygroupname") Then AddPrinterConnection "\\server\sharename"
0
pnrhaitCommented:
sorry forget to just add a network printer:

WshNetwork.AddWindowsPrinterConnection "\\server\sharename"

make sure to have the remove before the add
0
pnrhaitCommented:
could you please attach your script for me and I can modify it for you.
0
Ron MalmsteadInformation Services ManagerCommented:
This will delete networked printers...

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



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GTKINCAuthor Commented:
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
GTKINCAuthor Commented:
Do I have to name the specific printer in the script or can I set it to delete any network printers?  
0
pnrhaitCommented:
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
pnrhaitCommented:
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
GTKINCAuthor Commented:
Thanks for your efforts.  Both solutions worked great for me.  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.