Page 1 of 2 12>
Topic Options
#136076 - 2005-03-22 08:11 PM PrinterList() UDF only works on my machine.
technician Offline
Fresh Scripter

Registered: 2005-03-22
Posts: 9
I'm writing a KiXtart script that will remove all local printers and re-install the printers I choose. I've been playing around with the PrinterList() UDF by Allen and got it to list the printers on my personal machine (admin permissions, WinXP SP2) both local and network. I cannot get the same results from other workstations on my network (admin permissions, WinXP SP1). The only difference in machines is service pack 2 installed on my machine.

Here's a copy of the code I've been tinkering with:

Code:

COLOR w+/b

break on

$array=printerlist()

for each $printer in $array

? $printer

next

;if delprinterconnection($printer) = 0
; ? "Deleted printers!"
;else
; ? "Unable to remove printers!"
;endif

;if addprinterconnection("\\Calvin\Canon") = 0
; ? "Added printer \\Calvin\Canon"
;else
; ? "ERROR: Unable to add printer \\Calvin\Canon!"
;endif

;if setdefaultprinter("\\Calvin\Canon") = 0
; ? "Default printer is now set to \\Calvin\Canon"
;else
; ? "ERROR: Unable to set a default printer!"
;endif

EXIT

Function Printerlist(optional $remotepc,optional $displaymode)

dim $service,$printer,$printers,$printerdesc

if $remotepc=""

$remotepc='\\'+ @wksta

else

if not left($remotepc,2)="\\"

$remotepc='\\' + $remotepc

endif

endif

$Service=GetObject("winmgmts:{impersonationLevel=impersonate}!" + $remotepc + "\root\cimv2")

if not @error=0

exit @error

endif

$Printers=$service.execquery ('select * from Win32_Printer')

for each $printer in $printers

select

case $displaymode=1

if $printerdesc=""

$printerdesc=$printer.name + "," + $printer.portname

else

$printerdesc=$printerdesc + "|" + $printer.name + "," + $printer.portname

endif

case $displaymode=0

if $printerdesc=""

$printerdesc=$printer.name

else

$printerdesc=$printerdesc + "|" + $printer.name

endif

endselect

next

$printerlist=split($printerdesc,"|")

endfunction



Any ideas on how I could be slipping up?

Top
#136077 - 2005-03-22 08:22 PM Re: PrinterList() UDF only works on my machine.
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
How are you running the script, as a logon script or an admin script?

As your script is now, it would only poll the local computer.

Top
#136078 - 2005-03-22 08:26 PM Re: PrinterList() UDF only works on my machine.
technician Offline
Fresh Scripter

Registered: 2005-03-22
Posts: 9
I have kixtart running @ NETLOGON, so I login as admin and run \\CALVIN\NETLOGON\kix32.exe test.kix (test.kix resides in my network share which is mapped to z:\). I was planning on running it as a logon script, but have been calling it manually to make sure it works for now. I have verified that all the kix files have the correct permissions.

I am gunning for polling the local computer, since I have no way of knowing when these machines are on/off.

Top
#136079 - 2005-03-22 09:46 PM Re: PrinterList() UDF only works on my machine.
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
You might add some error checking, just stick these two lines after the printerlist line

? "Error: " + @error
? "Number of printers: " + ubound($array) + 1

What do you get?

Top
#136080 - 2005-03-23 04:08 PM Re: PrinterList() UDF only works on my machine.
technician Offline
Fresh Scripter

Registered: 2005-03-22
Posts: 9
On another workstation I receive the following message after inputting your code after $array=printerlist():

Quote:


ERROR: -2147217467
Number of printers: -11





I have one installed printer on the workstation which was there before I tried running the script.

When I run your code on my personal machine I receive the following:

Quote:


Error: 0
Number of printers: 61
SnagIt 7
pdfFactory Pro
Microsoft Office Document Image Writer
HP LaserJet 2300 Series PCL 5e
hp deskjet 990c
\\Calvin\Canon
\\CALVIN\PC Lab Laserjet





As you can see I don't have 61 printers installed, but maybe it's grabbing that from the number of drivers installed. It does display the correct printers installed on my machine though.

Top
#136081 - 2005-03-23 04:29 PM Re: PrinterList() UDF only works on my machine.
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA

The first problem with the counts is actually an easy one.

Try this instead: ? "Number of Printers: " + (val(ubound($array)) + 1)

The second problem appears to be a com error: try replacing the @error line with code below to find out what the error is.

Code:
 
cerror @error " " @serror

Function Cerror()
exit Iif(@error<0,VAL("&"+Right(DecToHex(@error),4)),@error)
Endfunction


Top
#136082 - 2005-03-23 05:54 PM Re: PrinterList() UDF only works on my machine.
technician Offline
Fresh Scripter

Registered: 2005-03-22
Posts: 9
Okay, now I'm getting some interesting information.

Quote:


4097 Error (317 / 13D) while retrieveing error information for 1001Win32_Printer
Error: 0





It's now outputting the correct # of printers

Top
#136083 - 2005-03-23 08:52 PM Re: PrinterList() UDF only works on my machine.
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Okay, so lets see the code that's producing the error.
Top
#136084 - 2005-03-23 08:56 PM Re: PrinterList() UDF only works on my machine.
technician Offline
Fresh Scripter

Registered: 2005-03-22
Posts: 9
Here's the complete script I'm playing with:

Code:

COLOR w+/b

break on

$array=printerlist()

? "Error: " + @error
;? "Number of printers: " + ubound($array) + 1
? "Number of Printers: " + (val(ubound($array)) + 1)

for each $printer in $array

? $printer

next

;if delprinterconnection($printer) = 0
; ? "Deleted printers!"
;else
; ? "Unable to remove printers!"
;endif

;if addprinterconnection("\\Calvin\Canon") = 0
; ? "Added printer \\Calvin\Canon"
;else
; ? "ERROR: Unable to add printer \\Calvin\Canon!"
;endif

;if setdefaultprinter("\\Calvin\Canon") = 0
; ? "Default printer is now set to \\Calvin\Canon"
;else
; ? "ERROR: Unable to set a default printer!"
;endif

EXIT

Function Printerlist(optional $remotepc,optional $displaymode)

dim $service,$printer,$printers,$printerdesc

if $remotepc=""

$remotepc='\\'+ @wksta

else

if not left($remotepc,2)="\\"

$remotepc='\\' + $remotepc

endif

endif

$Service=GetObject("winmgmts:{impersonationLevel=impersonate}!" + $remotepc +

"\root\cimv2")

; if not @error=0

; exit @error

; endif

cerror @error " " @serror

$Printers=$service.execquery ('select * from Win32_Printer')

for each $printer in $printers

select

case $displaymode=1

if $printerdesc=""

$printerdesc=$printer.name + "," + $printer.portname

else

$printerdesc=$printerdesc + "|" + $printer.name + "," + $printer.portname

endif

case $displaymode=0

if $printerdesc=""

$printerdesc=$printer.name

else

$printerdesc=$printerdesc + "|" + $printer.name

endif

endselect

next

$printerlist=split($printerdesc,"|")

endfunction

Function Cerror()
exit Iif(@error<0,VAL("&"+Right(DecToHex(@error),4)),@error)
Endfunction


Top
#136085 - 2005-03-23 09:03 PM Re: PrinterList() UDF only works on my machine.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and kix version?
_________________________
!

download KiXnet

Top
#136086 - 2005-03-23 09:10 PM Re: PrinterList() UDF only works on my machine.
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Couple of suggestions...
Don't change the UDFs at all, move the cerror line back into the top of your script immeditately following the printerlist line.

The code you provided still would only poll your pc, so unless I'm totally missing something here, can you please provide the code that you are using when you are polling other pcs, since that is when you are getting the errors.

Top
#136087 - 2005-03-23 09:30 PM Re: PrinterList() UDF only works on my machine.
technician Offline
Fresh Scripter

Registered: 2005-03-22
Posts: 9
Kix version is the latest stable off the website.

The code I posted here is what I ran on both my personal workstation and a random workstation out in my library, no changes (that's why it's stumping me that it would work one place and not another). When I mean running it I mean physically sitting down at the workstation and typing in \\CALVIN\NETLOGON\kix32.exe test.kix, not running any scripts over the network to poll a remote machine I am not sitting at.

I'll change the cerror deal as you mentioned. Will the output change enough to post it here?

Top
#136088 - 2005-03-23 09:49 PM Re: PrinterList() UDF only works on my machine.
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Thanks for explaining... and that is odd. Are you logging in as the same user on the different PCs? If not you might try it to see if its a permissions issue.

When I wrote this UDF, I'm sure it was done on Windows 2000 SP4 or SP3. So I feel pretty confident XP would work as well, regardless of it SP.

Top
#136089 - 2005-03-23 09:53 PM Re: PrinterList() UDF only works on my machine.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
right...
iirc, xp broke my getmac...
_________________________
!

download KiXnet

Top
#136090 - 2005-03-25 05:43 PM Re: PrinterList() UDF only works on my machine.
technician Offline
Fresh Scripter

Registered: 2005-03-22
Posts: 9
Quote:

Thanks for explaining... and that is odd. Are you logging in as the same user on the different PCs? If not you might try it to see if its a permissions issue.

When I wrote this UDF, I'm sure it was done on Windows 2000 SP4 or SP3. So I feel pretty confident XP would work as well, regardless of it SP.




Yes, I'm logging in as the exact same administrator account on both machines. Since the script is kept on a account share over the network, I even tried copying it to the local machine but it didn't make a difference.

This is very strange, has me completely stumped.

Top
#136091 - 2005-03-25 06:13 PM Re: PrinterList() UDF only works on my machine.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I say let alpo or someone else test it and prove it works on xp.
XP and w2k do not work the same way what comes to printers.
_________________________
!

download KiXnet

Top
#136092 - 2005-03-25 08:47 PM Re: PrinterList() UDF only works on my machine.
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I have no idea why its not working. I just tested it on my XP SP2 box with no problems.

Output:
PDF995
Intuit Internal Printer
HP LaserJet 1100 (MS)
Fax
Auto HP LaserJet 1100 (MS) on HOMEPC

Jooel...man you are anti-XP...

Top
#136093 - 2005-03-25 08:55 PM Re: PrinterList() UDF only works on my machine.
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Hey Tech... you might try running Kixomatic on the machines you are having trouble with, and see if it has anything to do with WMI.
Top
#136094 - 2005-03-28 05:02 PM Re: PrinterList() UDF only works on my machine.
technician Offline
Fresh Scripter

Registered: 2005-03-22
Posts: 9
Just a little update, I went into one of my computer labs and ran the script on a machine in there (settings are identical as far as I'm aware) and it [the script] worked perfectly. Now I'm pulling my hair trying to figure out what in the world is different between these PCs. Is WMI a package I can download and run from Microsoft?
Top
#136095 - 2005-03-28 07:27 PM Re: PrinterList() UDF only works on my machine.
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
WMI is included in the newer versions of Windows. Win2K and XP got it embedded and for 9x and NT4 it can be downloaded from here
http://www.microsoft.com/downloads/detai...;displaylang=en

What is WMI you ask?
A quote from MS:
Quote:


Windows Management Instrumentation (WMI) makes Windows extremely manageable using a single consistent, standards-based, extensible and object-orientated interface. WMI is the Microsoft implementation of Web-Based Enterprise Management (WBEM), an industry initiative to develop a standard technology for accessing management information in an enterprise environment. This initiative helps companies lower their total cost of ownership by enabling powerful management of systems, applications and devices.





Edited by R2D2 (2005-03-28 07:28 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.088 seconds in which 0.039 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org