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
773 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Email signature management is something that is often overlooked in many organizations or is simply not implemented effectively. Let's take a look at what methods are available for managing this important piece of corporate branding.
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

13 Experts available now in Live!

Get 1:1 Help Now