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
784 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
[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
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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Let’s face it: one of the reasons your organization chose a SaaS solution (whether Microsoft Dynamics 365, Netsuite or SAP) is that it is subscription-based. The upkeep is done. Or so you think.
We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

690 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