Scripts Thread, problems with my printer Script, can you cast your eye over it? in Coding and Web Development; I keep get intermittent problems with the script we have been running for a longtime. It's normally flawless but now ...
-
17th November 2009, 11:22 AM #1 problems with my printer Script, can you cast your eye over it?
I keep get intermittent problems with the script we have been running for a longtime. It's normally flawless but now for some reasons I get errors.
* Sometimes the correct printers are shown and loaded sometimes they are not.
*pretty much everyone gets an erroneous printer which does not exist and is not in the script, from one of our old servers, can not find anywhere where it is running.
Keep getting script errors:
Script: xxxxxxxx
Line: 10
Char: 5
Error: Generic
Code: 80041001
Source: SWBemOBJECTEx
Script is below, Thanks :
Code:
'This Deletes all mapped printers for the user
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Network = True")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
'***********************************************
'This checks the name of the machine and applies the printer path
Dim oNetwork, sPrintPath, sShort
Set oNetwork = CreateObject("WScript.Network")
sShort = Left (oNetwork.ComputerName, 4)
Select Case sShort
Case "MUS2"
sPrintpath = "\\140_T_MUSIC\MUSICPRINT"
Case "TEX_"
sPrintpath = "\\support\textiles"
Case "SEN0"
sPrintPath = "\\support\116"
Case "117A"
sPrintPath = "\\support\Laserjet 117B"
Case "117B"
sPrintPath = "\\support\Laserjet 117C"
Case "STR_"
sPrintPath = "\\support\Staffroom"
Case "129_"
sPrintPath = "\\support\Brother HL-1440 -129-"
Case "204A"
sPrintPath = "\\support\LaserJet -204A-"
Case "204B"
sPrintPath = "\\support\Laserjet -204B-"
Case "204C"
sPrintPath = "\\support\LaserJet -204C-"
Case "64_A"
sPrintPath = "\\support\Laserjet -64A-"
Case "64_B"
sPrintPath = "\\support\Laserjet -64B-"
Case "65_A"
sPrintPath = "\\support\Brother65"
Case "KB4A"
sPrintPath = "\\support\K4A"
Case "KB4B"
sPrintPath = "\\support\K4B"
Case "LLRC"
sPrintPath = "\\support\LLRC"
Case "ART2"
sPrintPath = "\\support\ART1"
Case "M1_T"
sPrintPath = "\\support\MFL"
Case "M2_T"
sPrintPath = "\\support\MFL"
Case "M3_T"
sPrintPath = "\\support\MFL"
Case "ENG_"
sPrintPath = "\\support\English"
Case "SCLT"
sPrintPath = "\\support\Science"
Case "FTEC"
sPrintPath = "\\support\FoodTech"
Case "ENG2"
sPrintPath = "\\support\English_2"
Case Else
WScript.Quit
End Select
oNetwork.AddWindowsPrinterConnection sPrintPath
oNetwork.SetDefaultPrinter sPrintPath
'**************************************************************
'This applies secondary printers(colour) to the user
Select Case sShort
Case "64_A"
sPrintPath = "\\support\A3_64Colour"
Case "64_B"
sPrintPath = "\\support\A3_64Colour"
Case "65_A"
sPrintPath = "\\support\HPcolour - 65"
Case "204A"
sPrintPath = "\\support\204colour"
Case "204B"
sPrintPath = "\\support\204colour"
Case "204C"
sPrintPath = "\\support\204colour"
Case "117A"
sPrintPath = "\\support\117_colour"
Case "117B"
sPrintPath = "\\support\117_colour"
Case "SCLT"
sPrintPath = "\\support\ScienceColour"
Case "KB4A"
sPrintPath = "\\support\K4_COLOUR"
Case "KB4B"
sPrintPath = "\\support\K4_COLOUR"
Case Else
WScript.Quit
End Select
oNetwork.AddWindowsPrinterConnection sPrintPath
'**************************************************************
'This applies a third printer to the user
select Case sShort
Case "64_A"
sPrintPath = "\\support\A4_64Colour"
Case "64_B"
sPrintPath = "\\support\A4_64Colour"
Case "65_A"
sPrintPath = "\\support\65_A4_Colour"
Case Else
WScript.Quit
End Select
oNetwork.AddwindowsPrinterConnection sPrintPath
-
-
IDG Tech News
-
17th November 2009, 12:44 PM #2 
Originally Posted by
jinnantonnix
The underscore is telling the interpreter to append the following line as if it were a continuation, isn't it?
No. This is one of the wacky bits of method names in chunks of the Windows API; they end with an underscore just to make life difficult :-)
Is the error reproducible (ie always for 1 user, 1 machine etc??) If so, can you try putting in an "on error resume next" at the beginning of the code and then this:
Code:
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
if err.number<>0 then
wscript.echo objPrinter.name
end if
Next that will at least tell you which printer is not deleting.
The 0x80040001 error seems to be pretty non-specific ("something's gone wrong but I don't know what!") but there's some stuff here Code 80041001 - VBScript Error called failed which may help; particularly about clearing out the WBEM repository.
-
-
17th November 2009, 12:51 PM #3 Code:
' killprinters.vbs
Option Explicit
Dim objNetwork
on error resume next
Set objNetwork = CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection "\\server\lasercol", true, true
objNetwork.RemovePrinterConnection "\\server\colourlt", true, true not sure if this helps at all but thats my printer removal script
-
-
17th November 2009, 01:11 PM #4 I use a script that picks up the OU of the computer, so when i move a machine in AD (say from year4 classroom to year 5 classroom) it will change the printer for me.
my script is better explained here: Printer Script that uses a computers Active Directory OU - Blog.Arcath.Net
-
SHARE:
Similar Threads
-
Replies: 164
Last Post: 1st October 2010, 10:11 AM
-
By chrbb in forum Scripts
Replies: 1
Last Post: 11th July 2008, 12:27 PM
-
By martyn in forum Scripts
Replies: 13
Last Post: 20th February 2008, 05:29 PM
-
Replies: 9
Last Post: 14th September 2007, 08:30 AM
-
By Galway in forum Windows
Replies: 3
Last Post: 29th August 2007, 11:00 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