Windows Server 2000/2003 Thread, Removing Network Printer in Technical; Morning,
I currently have a VB script that maps all the printers when people logon.
Now i'm having a problem ...
-
28th June 2010, 10:01 AM #1 Removing Network Printer
Morning,
I currently have a VB script that maps all the printers when people logon.
Now i'm having a problem with my staff one. After a bit of fiddling I have managed to get a long neglected printer working in the staff room, but unfortunately it is appearing twice on their printer list. The working one is Staff-Room but its also bringing up Staff Room which throws up an error message.
The script is in this format...
Code:
if left(compname,4) = "INFS" then
PrinterPath = "\\curricsvr1\JUNIOR-SUITE"
PrinterPath2 = "\\curricsvr1\INFANT-SUITE"
PrinterPath3 = "\\curricsvr1\FOUNDATION"
PrinterPath4 = "\\curricsvr1\INFANT-LIBRARY"
PrinterPath5 = "\\curricsvr1\STAFF-ROOM"
WshNetwork.AddwindowsPrinterConnection PrinterPath
WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.AddwindowsPrinterConnection PrinterPath3
WshNetwork.AddwindowsPrinterConnection PrinterPath4
WshNetwork.AddwindowsPrinterConnection PrinterPath5
WshNetwork.SetDefaultPrinter "\\curricsvr1\INFANT-SUITE"
end if
-
-
IDG Tech News
-
28th June 2010, 10:04 AM #2
- Rep Power
- 0
I delete all printers first, then add them:
Code:
Set WshNetwork = CreateObject("WScript.Network")
On Error Resume Next
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 1 to oPrinters.Count - 1 Step 2
WshNetwork.RemovePrinterConnection oPrinters.Item(i)
Next
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\Server01\printer01"
WshNetwork.AddWindowsPrinterConnection "\\Server01\printer02"
WshNetwork.AddWindowsPrinterConnection "\\Server01\printer03"
rem ** Setup default printer **
WshNetwork.SetDefaultPrinter "\\Server01\Printer02"
-
2 Thanks to ted_baker:
Little-Miss (28th June 2010), stevenlong1985 (2nd November 2010)
-
28th June 2010, 10:09 AM #3 Same here, our script deletes all printers first, then re-adds them. This ironed out a few quirks.
-
Thanks to 3s-gtech from:
Little-Miss (28th June 2010)
-
28th June 2010, 10:38 AM #4 so, if i add...
Code:
on error resume next
Set WshNetwork = CreateObject("WScript.Network")
Dim Compname
Compname = WSHNetwork.ComputerName
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 1 to oPrinters.Count - 1 Step 2
WshNetwork.RemovePrinterConnection oPrinters.Item(i)
Next
if left(compname,4) = "INFS" then
PrinterPath = "\\curricsvr1\JUNIOR-SUITE"
PrinterPath2 = "\\curricsvr1\INFANT-SUITE"
PrinterPath3 = "\\curricsvr1\FOUNDATION"
PrinterPath4 = "\\curricsvr1\INFANT-LIBRARY"
PrinterPath5 = "\\curricsvr1\STAFF-ROOM"
WshNetwork.AddwindowsPrinterConnection PrinterPath
WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.AddwindowsPrinterConnection PrinterPath3
WshNetwork.AddwindowsPrinterConnection PrinterPath4
WshNetwork.AddwindowsPrinterConnection PrinterPath5
WshNetwork.SetDefaultPrinter "\\curricsvr1\INFANT-SUITE"
end if to my script like this it should work?
-
-
28th June 2010, 10:42 AM #5
- Rep Power
- 0
Try it, but on a test PC first.
-
-
1st October 2010, 08:53 PM #6 Downfall of course of removing all printers is that you will lose any local printers you might have installed on local machines as well as delaying your login.
If you're running a large network with many networked printers you might find it takes a while to remap them all. In your instance, its probably best to remove that troublesome printer and leave the other printers be. Saves you time and solves the issue. Unless of course you only have like < 8 printers or something, then it shouldn't make too much of a big deal, but watch your local printers. (if any)
-
-
2nd October 2010, 09:37 AM #7 I'm not sure but I don't believe that script would delete locally installed printers.
Wes
-
-
2nd October 2010, 10:25 AM #8 
Originally Posted by
wesleyw
I'm not sure but I don't believe that script would delete locally installed printers.
Wes
Am sure RIC's post is still on edugeek somewhere ref the printer script he did - you could take the bit of coding at the start ref the If statement to check if it is an LPR or USB connection and if so to ignore it otherwise to remove the printer connections as per the chunk of code you added at the start of your snippet and leave the rest of your code as is
-
-
4th October 2010, 09:02 AM #9 You could avoid scripting altogether and use client side extensions, if not to map the printers then there is atleast the option to remove all networked printers. Really it's so easy to deploy printers with CSE, as long as it's not on vista.
-
-
4th October 2010, 01:00 PM #10 
Originally Posted by
mac_shinobi
You could take the bit of coding at the start ref the If statement to check if it is an LPR or USB connection and if so to ignore it otherwise to remove the printer connections
Or alternatively you could simply perform an IF Statement to see if the printer's name begins with "\\" . Not sure how complex it is to check for USB or LPR, but I introduced a code in my login script to just check the name. Similar to the below.
Code:
'Remove all Network printers but not local printers
Set Printers = WshNetwork.EnumPrinterConnections
If ObjFSO.FileExists(strDirectory & strFile) = false Then
For i = 0 to Printers.Count - 1 Step 2
If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
End IF
Next Obviously you would need to change to match your defined objects.
Thats what I use anyway. In some cases a login script might not remove local printers, it depends on the script and what commands you have used, I think anyway.
-
-
6th October 2010, 11:47 AM #11 this removes printers but leaves ltp and usb ones alone
Code:
For i = 0 to oPrinters.Count - 1 Step 2
On Error Resume Next
if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then
WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
else WScript.Echo "No network printers found"
end if
Next BoX
Last edited by box_l; 6th October 2010 at 11:50 AM.
-
-
13th October 2010, 02:26 PM #12 We use rundll32 commands in a login script to delete all installed printers, then to install the printer specific to that room.
E.G.
rundll32 printui.dll,PrintUIEntry /dn /q /n\\servername\printersharename - deletes a printer
rundll32 printui.dll,PrintUIEntry /in /q /n\\servername\printersharename - installs printer
Works for us, script runs at log-on, takes about 10 seconds......means a different batch file for every room, but once they're done, they're done.
And I don't know about anyone else, but it looks like being a long time before we install or refurbish any new or existing rooms. Or even buy any new printers.
-
SHARE: 
Similar Threads
-
By Matt4 in forum Windows
Replies: 5
Last Post: 30th May 2010, 08:10 PM
-
By VladVanca in forum Windows
Replies: 0
Last Post: 30th May 2010, 08:04 PM
-
By HiredGoon in forum Wireless Networks
Replies: 3
Last Post: 5th June 2008, 02:35 PM
-
By ICTNUT in forum Windows
Replies: 22
Last Post: 14th March 2008, 02:57 PM
-
By Paid_Peanuts in forum Hardware
Replies: 5
Last Post: 26th February 2008, 09:55 AM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules