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?