Sign in to follow this  
Followers 0
4Eyes

Can't interrogate a remote pc with WMI

4 posts in this topic

#1 ·  Posted (edited)

Folks,

While using WMI to get info from a remote pc on a LAN (workgroup not domain) I find that any that don't use the same local username and password as the pc running the script fail. Passing the appropriate username and password for that remote pc doesn't help. Both PC's are running XP Pro SP3 and the firewall is disabled on both. Please note that this DOES work on all pc's that share the same username and password, and no, it is not possible to change the rest to suit.

(EDIT) BTW, this problem occurs with other programs, namely Network View, WMI Explorer and every blasted VB script I download from MS or others. Sigh and Grrrrr!

I see several previous threads here related to this issue but none shed any light. Amongst others:

This is the code I am using to test with:

#include <IE.au3>

Global $objSWbemLocator, $objSWbemServices

_IEErrorHandlerRegister()                                                                               ; This is so we can have a quick and easy COM Error Handler

$strComputer = "Change this"
$strUser = "Change this"
$strPassword = "Change this"

;$strComputer = "192.168.1.100"                                                                         ; This is my pc...
;$strUser = ""                                                                                          ; so don't need to pass credentials
;$strPassword = ""

$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
If Not IsObj($objSWbemLocator) Then
    ConsoleWrite("Error: Failed to create $objSWbemLocator")
    Exit
EndIf

$objSWbemServices = $objSWbemLocator.ConnectServer($strComputer, "root\cimv2", $strUser, $strPassword)  ; This doesn't work
;$objSWbemServices = $objSWbemLocator.ConnectServer($strComputer, "root\cimv2", "", "")                 ; This works for local pc - IE do NOT attept to pass credentials
If Not IsObj($objSWbemServices) Then
    ConsoleWrite("Error: Failed to create $objSWbemServices")
    Exit
EndIf

$objSWbemServices.Security_.ImpersonationLevel = 3

$colItems = $objSWbemServices.ExecQuery("select * from Win32_ComputerSystem")
If IsObj($colItems) Then
    For $objItem In $colItems
        $PCName = $objItem.Caption
    Next
    ConsoleWrite("$PCName = " & $PCName & @CRLF)
Else
    ConsoleWrite("$objSWbemServices.ExecQuery() failed" & @CRLF)
EndIf

This is the error reported:

--> COM Error Encountered in WMITest.au3

----> $IEComErrorScriptline = 33

----> $IEComErrorNumberHex = 80020009

----> $IEComErrorNumber = -2147352567

----> $IEComErrorWinDescription = Access is denied.

----> $IEComErrorDescription = Access is denied.

----> $IEComErrorSource = SWbemLocator

----> $IEComErrorHelpFile =

----> $IEComErrorHelpContext = 0

----> $IEComErrorLastDllError = 0

Error: Failed to create $objSWbemServices

I can honestly say this is driving me ratso. I'd really appreciate any help with this.

Regards,

4Eyes

Edited by 4Eyes

Share this post


Link to post
Share on other sites



you might get some answers here

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/e03e4a5b-de68-49ff-987a-6c3571eb4ff7/

Share this post


Link to post
Share on other sites

TheCurrent,

Thanks for that link but unfortunately it didn't help as it uses .Net Framework stuff.

Come on guys. This is relatively easy for someone to test. I've tried it on 2 different LANs and found multiple programs that just don't work. I'd really like someone to test it to confirm whether I've lost my marbles or it's a major bug in Windows... or am I just doing something wrong?

The first post has example code that changes nothing on the pc's involved. Could someone please test this and advise?

4Eyes

Share this post


Link to post
Share on other sites

Ok, egg on face time again. The code I posted works, but what I was testing was not the same code... I made a typo.

4Eyes

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0