#171499 - 2006-12-14 03:23 PM
Is WMI Broke?
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
This script seams to work fine for the local computer but if I try to use a remote computer name it does not work. I have all windows firewalls disabled so that should not have anything to do with it. Could you test this script on your network then let me know how it works?
GetWMIPrinters("NetAdmin2")
Function GetWMIPrinters($Computer)
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery("Select * from Win32_Printer")
For Each $objPrinter in $colInstalledPrinters
? "Name: " + $objPrinter.Name
? "Location: " + $objPrinter.Location
? "Default: " + $objPrinter.Default
Next
EndFunction
|
Top
|
|
|
|
#171501 - 2006-12-14 03:34 PM
Re: Is WMI Broke?
[Re: Richard H.]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
you mean something like:
Function GetWMIPrinters($Computer)
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\cimv2")
If Not(@ERROR = 0)
? @ERROR
EndIf
$colInstalledPrinters = $objWMIService.ExecQuery("Select * from Win32_Printer")
If Not(@ERROR = 0)
? @ERROR
EndIf
For Each $objPrinter in $colInstalledPrinters
? "Name: " + $objPrinter.Name
? "Location: " + $objPrinter.Location
? "Default: " + $objPrinter.Default
Next
EndFunction
|
Top
|
|
|
|
#171502 - 2006-12-14 03:48 PM
Re: Is WMI Broke?
[Re: Benny69]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
If that is what you mean, i receive no errors.
|
Top
|
|
|
|
#171503 - 2006-12-14 03:51 PM
Re: Is WMI Broke?
[Re: Benny69]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Basically yes, though personally I'd prefer something a bit more like this:
Dim $colInstalledPrinters,$objPrinter
$colInstalledPrinters=GetWMIPrinters(".")
If @ERROR "Could not retrieve printers: ["+@ERROR+"] "+@SERROR+@CRLF Exit @ERROR EndIf
For Each $objPrinter in $colInstalledPrinters
"Name: " + $objPrinter.Name + @CRLF
"Location: " + $objPrinter.Location + @CRLF
"Default: " + $objPrinter.Default + @CRLF
Next
Function GetWMIPrinters($Computer)
Dim $objWMIService
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\cimv2")
If @ERROR Exit @ERROR EndIf
If VarType($objWMIService)<>9 Exit 2 EndIf
$GetWMIPrinters=$objWMIService.ExecQuery("Select * from Win32_Printer")
Exit @ERROR
EndFunction
Edited by Richard H. (2006-12-14 03:53 PM)
|
Top
|
|
|
|
#171504 - 2006-12-14 03:56 PM
Re: Is WMI Broke?
[Re: Richard H.]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
ok, tried your script and as with mine it works localy but not remotely and i receive no errors.
|
Top
|
|
|
|
#171506 - 2006-12-14 04:14 PM
Re: Is WMI Broke?
[Re: Richard H.]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
nope, nothing. It works for you on your network? A few days ago I asked Doc to test it on his network and he said it did not work for him. He thought that there might have been some recent security change in microsoft.
|
Top
|
|
|
|
#171509 - 2006-12-14 04:21 PM
Re: Is WMI Broke?
[Re: Richard H.]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
idk, if i go to the remote machine and run the script localy it returns all the printers on that machine, it just does not seam to want to work remotely. The strainge thing is, that this is the suggested script by microsoft to look at remote computers. I think they have changed something and they are not admiting to it.
I have also tried to look at the remote registry with the same results:
$SubKeys = GetPrinterList("NetAdmin2")
$SubKeys = Split($SubKeys,",")
For Each $Key in $SubKeys
? $Key
Next
Function GetPrinterList($Computer)
If @INWIN = 1
;$GetPrinterList = GetSubKeyValues("\\"+$sComputer+"\HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices")
$GetPrinterList = GetSubKey("\\"+$Computer+"\HKCU\Printers\Connections")
Else
EndIf
EndFunction
Function GetSubKey($SubKey)
Dim $Index
$Index = 0
$Key = EnumKey($Subkey,$Index)
While @ERROR = 0
If $GetSubKey = ""
$GetSubKey = $Key
Else
$GetSubKey = $GetSubKey + "," + $Key
EndIf
$Index = $Index + 1
$Key = EnumKey($Subkey,$Index)
Loop
EndFunction
|
Top
|
|
|
|
#171513 - 2006-12-14 04:35 PM
Re: Is WMI Broke?
[Re: Richard H.]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Ok, that would explain why it does not work when I try to look at the remote registry. I am still confused as to why the WMI does not work.
|
Top
|
|
|
|
#171516 - 2006-12-14 04:59 PM
Re: Is WMI Broke?
[Re: Richard H.]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
What you guys are saying makes some sence, but in the microsoft script repository the description for this script says, 'Lists all the printer connections on a computer.' It does not elude to anything that would be constricted by whatever user is logged on.
List Printer Connections Description Lists all the printer connections on a computer. Supported Platforms Windows Server 2003 Yes Windows XP Yes Windows 2000 No Windows NT 4.0 No Windows 98 No Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Name: " & objPrinter.Name
Wscript.Echo "Location: " & objPrinter.Location
Wscript.Echo "Default: " & objPrinter.Default
Next
|
Top
|
|
|
|
#171520 - 2006-12-14 06:46 PM
Re: Is WMI Broke?
[Re: Benny69]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
I know my UDF worked in the past and its doing pretty much the same wmi code... try it and see what kind of results you get: PrinterList()
|
Top
|
|
|
|
#171521 - 2006-12-14 06:59 PM
Re: Is WMI Broke?
[Re: Allen]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Allen, Your code as i used it:
Break on
$RC=SetOption("WrapAtEOL","on")
$array=PrinterList("NetAdmin2",0)
For Each $printer in $array
? $printer
Next
Get $a
Function PrinterList(optional $remotepc, optional $displaymode)
Dim $service,$printer,$printers,$printerdesc[0],$counter,$portname,$printername
If $remotepc=""
$remotepc="."
EndIf
$Service = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
If @error
Exit @error
EndIf
$Printers=$service.execquery ('select * from Win32_Printer')
For Each $printer in $printers
ReDim preserve $printerdesc[$counter]
If $displaymode & 1
$portname = "," + $printer.portname
EndIf
Select
Case $displaymode & 4 ;remote printers
If Left($printer.portname,2)="\\" Or Left($printer.name,2)=="\\"
$printername=$printer.name
EndIf
Case $displaymode & 2 ;local printers
If Left($printer.portname,2)<>"\\" And Left($printer.name,2)<>"\\"
$printername=$printer.name
EndIf
Case 1 ; all printers
$printername=$printer.name
EndSelect
If $printername<>""
$printerdesc[$counter]=$printername + $portname
$counter=$counter + 1
$printername=""
EndIf
Next
$PrinterList=$printerdesc
EndFunction
I get the same results, it works localy but not remotely.
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
2 registered
(morganw, mole)
and 414 anonymous users online.
|
|
|