Solved

Network Printer Connections in Group Policy via batch file or vbs. Cannot delete old printers correctly. They reapear after deletion!

Posted on 2011-03-22
6
769 Views
Last Modified: 2012-05-11
I have written a simple batch file to run via group policy that connects to our network shares and deletes all local users printers, a vbs script is then run which installs a new Colour laser printer shared by the domain controller server.

This has been tested under a staff login with access to the printers and faxes window. And the the batch file deletes all priunter connections and then running the vbs file created a single network printer connection.

Unfortunately when I include them in group policy..strange things happen.

When Logging on;
Shares are connected but when I try to print there are three old printer connections present and the new printer connection is not visable. I have tried putting the batch file in a shared resource and running them again after loging on and they work fine. The first file the batch file connects to the relevant shares and deletes all printer connections. I then run the vbs script which installs the new network printer connection! All good.

So I looked into the group policy management, I removed all logon scripts in the default domain policy, I checked using gpedit.msc the local PCs had not got any logon scripts and I logged on locally to the administrator account and deleted all the printer connections (there were the 3 old connections that keep being populated) I logged on as the domain administrator on the workstation and again deleted all printer connections. I logged onto the server and checked there was only the new printer installed and shared.

I don't understand why the old printer connections are being populated and why the new connection is never present. Please any suggestions would really help
0
Comment
Question by:edgeit
6 Comments
 
LVL 3

Accepted Solution

by:
bull_dog9 earned 167 total points
ID: 35188713
Is the script your trying to push in the login section or the logon section of the GPO?
It should be on the login section for the user to have the printers.

Are you using a print server to share your printer? Are the correct drivers installed on that server?
Make shore the correct rights are on the driver repository.

Did you change the share and printer name of the printer old vs new?
Try changing the share and printer name of the new printer.

See Example 2 to remove a printer fully with VBS
http://www.computerperformance.co.uk/Logon/Logon_Remove_Printer.htm#Example_2_-_Full_RemoveNetworkDrive_Syntax_

see code below to add a printer


'########################################################
				'Printer Mapping
				'########################################################

		wshNetwork.AddWindowsPrinterConnection "\\APPS01\Xerox ColorQube 9000 PS"

Open in new window

0
 

Author Comment

by:edgeit
ID: 35189217
Hi thanks for the reply, I currently have the the files loaded in GPO - User Config - Windows Settings - Logon Script

The printer has a 10/100 network interface with the correct drivers. I can add the printer via the run command and it works and prints.

How do I make sure the correct sharing rights are on the driver repository?

I will try renaming the printer share names this afternoon.

I will try adding the printer via vbs coding as you have suggested this afternoon too.

Kind Regards

James
0
 
LVL 1

Assisted Solution

by:lvanalstyne
lvanalstyne earned 166 total points
ID: 35189223
Not sure if this is what you're using in your batch file, but I use printui for this sort of thing.
Documentation here: http://download.microsoft.com/download/8/2/c/82cffcfa-56f6-4fc3-bfa5-80cd84793871/PrintUIUsersGuide.doc

To delete a local printer:

rundll32 printui.dll PrintUIEntry /dl /n"Exact name of printer"

where the "Exact name" is what shows up in the Printers & Faxes dialog.

Don't know what else you are doing with the vbs script, but you can also add printers with this. May be faster if you don't have anything else you are doing in the script.

Add network printer:
rundll32 printui.dll PrintUIEntry /ga /n"\\server\printershare"

Note: If you add a printer using this /ga method, you must delete it using /gd. Or else it will come back.

Note #2: PrintUIEntry is case sensitive

you can also delete drivers and do lots of things with it.
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 13

Assisted Solution

by:BCipollone
BCipollone earned 167 total points
ID: 35191234
Delete the printers from the registry:

http://support.microsoft.com/kb/102116
0
 

Author Comment

by:edgeit
ID: 35199805
Hi Again,

I am now using vbs code to firstly delete all printers first, then to push the new printer connection then finally to set it as the default printer. The code I am using is below;

Set WS_NET = CreateObject("wscript.network")
            Set WS_PRINTERS = WS_NET.EnumPrinterConnections
            For LOOP_COUNTER = 0 To WS_PRINTERS.Count - 1 Step 2
                MsgBox WS_PRINTERS(LOOP_COUNTER) & vbTab & WS_PRINTERS(LOOP_COUNTER + 1)
                WS_NET.removeprinterconnection WS_PRINTERS(LOOP_COUNTER + 1)
                WS_NET.removeprinterconnection WS_PRINTERS(LOOP_COUNTER)
            Next
            Set WS_PRINTERS = Nothing
            Set WS_NET = Nothing

' Printers.vbs - Windows Logon Script.
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\2003server\ICT-COLOUR"

'  Example VBScript to set the local Default Printer
'  Guy Thomas February 2004.
'  ******************************
'Option Explicit
Dim objPrinter
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter "\\2003server\ICT-COLOUR"
' End of example VBScript

When run First I recieve a message;

IP_10.127.160.53 \\2003server\HP Colour Laser Jet 2600n

Then an Script Host error;

Line 5

Char 17

error: This network connection does not exist

I check under printers and faxes and there are still 2 server based printer connections!!

0
 
LVL 3

Expert Comment

by:bull_dog9
ID: 35199876
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How can you create a game plan that lets you focus on special projects instead of running from cubicle to cubicle every day and feeling like you’ve accomplished nothing? Try these strategies for prioritizing your tasks, offloading what you can, and …
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

15 Experts available now in Live!

Get 1:1 Help Now