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
770 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
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.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

947 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

22 Experts available now in Live!

Get 1:1 Help Now