#161606 - 2006-05-05 09:22 AM
WMI Query on remote Computer
|
krex
Fresh Scripter
Registered: 2006-03-02
Posts: 39
|
Hi! What do you need to get printers from a remote Server i am on a win xp with sp 2 and i want to get the printers from a windows 2003 server with sp 1. Now do i need 2 be log on my win xp with a domain admin or a power user to get access to the remote computer or smething like that...?
I tryede this: Code:
$sComputer = "MyServer" $Service = GetObject("winmgmts:\\+$sComputer+\root\cimv2") IF @Error ? @Error Endif
I get this error: -2147217405 This code is from the Printer UDF
Thanks!
|
|
Top
|
|
|
|
#161610 - 2006-05-05 07:31 PM
Re: WMI Query on remote Computer
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Quote:
domain account that has admin rights on the remote computer
Well not to be a stickler but that's not true either. The account does not need to be from the Domain either, it just needs to be on that local computer and specified as part of the call a little differently is all.
Though using a Domain account with admin rights is the normal and easier method.
|
|
Top
|
|
|
|
#161611 - 2006-05-06 08:15 PM
Re: WMI Query on remote Computer
|
ChristopheM
Hey THIS is FUN
   
Registered: 2002-05-13
Posts: 311
Loc: STRASBOURG, France
|
with the original piece of code published, you have to be connected on the workstation with a domain account that has admin right on the remote computer.
if you want to execute wmi command with a local account of the remote computer, you must add lines in the script to connect first to the remote wmi system.
A good example is given at "Problem with semisyncronous WMI query" in KiXtart bulletinboard.
There is a block like Code:
if $username and $computer<>'.' ; create locator object for connection to a remote computer $objLocator = CreateObject('WbemScripting.SWbemLocator') if @ERROR exit @ERROR endif ; create a (credentialed, if username/password provided) connection to a remote computer $objWBEM=$objLocator.ConnectServer($computer,$namespace,$username,$password) if @ERROR exit @ERROR endif ; set the impersonation level $objWBEM.Security_.ImpersonationLevel = 3 if @ERROR exit @ERROR endif endif
first, you create an object for WbemLocator second, you connect to the remote computer (and here, you can use a local account of the remote computer) third, you set impersonation level.
this is more complex than using Code:
$Service = GetObject("winmgmts:\\+$sComputer+\root\cimv2")
_________________________
Christophe
|
|
Top
|
|
|
|
#161612 - 2006-05-08 03:07 PM
Re: WMI Query on remote Computer
|
krex
Fresh Scripter
Registered: 2006-03-02
Posts: 39
|
Hi! Thanks to all just what i needed
|
|
Top
|
|
|
|
#161614 - 2006-09-29 04:21 PM
Re: WMI Query on remote Computer
|
Rory Daniels
Getting the hang of it
Registered: 2003-02-25
Posts: 64
Loc: Bristol, UK
|
Code:
Function WMIGetPrinter($hostname) $WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Hostname + "\root\cimv2") If @Error > 0 $WMIGetPrinter = 1 Else $Printers = $WMIService.ExecQuery("Select * from Win32_PrinterConfiguration") If @Error > 0 $WMIGetPrinter = 1 Else For Each $Printer in $Printers If Left($printer.Name,2) = "\\" ? "Network Printer: " + $Printer.Name Else ? "Local Printer: " + $Printer.Name $LocalPrinters = $WMIService.ExecQuery("Select * from Win32_Printer where Win32_Printer.Name = '$Printername'") For Each $LocalPrinter in $LocalPrinters ? "Location: " + $LocalPrinters.Location ? "Default: " + $LocalPrinters.Default Next EndIf Next ? $WMIGetPrinter = 0 EndIf EndIf EndFunction
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 2419 anonymous users online.
|
|
|