Page 1 of 1 1
Topic Options
#161606 - 2006-05-05 09:22 AM WMI Query on remote Computer
krex Offline
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
#161607 - 2006-05-05 12:09 PM Re: WMI Query on remote Computer
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 311
Loc: STRASBOURG, France
if you use wmi connection with impersonnation, you need to be connected as an domain admin on your workstation.

you should also change your code. You wrote :
$Service = GetObject("winmgmts:\\+$sComputer+\root\cimv2")

but it should be
$Service = GetObject("winmgmts:\\"+$sComputer+"\root\cimv2")
_________________________
Christophe

Top
#161608 - 2006-05-05 03:17 PM Re: WMI Query on remote Computer
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Well, not necessarily domain admin, but an account with local administrator rights on the remote computer.
Top
#161609 - 2006-05-05 04:04 PM Re: WMI Query on remote Computer
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 311
Loc: STRASBOURG, France
yes.

i just wanted to say that you can't be connected with a local account on the workstation.
you must be connected on the workstation with a domain account that has admin rights on the remote computer.
_________________________
Christophe

Top
#161610 - 2006-05-05 07:31 PM Re: WMI Query on remote Computer
NTDOC Administrator Offline
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 Offline
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 Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 39
Hi!
Thanks to all just what i needed

Top
#161613 - 2006-05-09 05:52 AM Re: WMI Query on remote Computer
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See also fnWMIAuthentication() - Authenticates against a local or remote WMI provider
_________________________
There are two types of vessels, submarines and targets.

Top
#161614 - 2006-09-29 04:21 PM Re: WMI Query on remote Computer
Rory Daniels Offline
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
Page 1 of 1 1


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

Who's Online
0 registered and 2419 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.061 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

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