Jump to content

Utilizing Win32 classes remotely


Recommended Posts

Trying to remotely connect to a machine on my network. Found this resource from microsoft. So I tried to rewrite it and I'm getting an error on line 3

$objSWbemLocator = ObjGet("WbemScripting", "SWbemLocator")
ConsoleWrite(@error & @CR)
$objWMIService = $objSWbemLocator.ConnectServer("hostame", "rootcimv2", "domainuser", "password")

C:Documents and SettingsuserDesktopTestScriptsTEST_DONT_SAVE.au3 (3) : ==> Variable must be of type "Object".:

$objWMIService = $objSWbemLocator.ConnectServer("hostame", "rootcimv2", "domainuser", "password")

$objWMIService = $objSWbemLocator^ ERROR

ConsoleWrite() returns -2147221020

Is my ObjGet() incorrect for my usage?

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

That page shows it using ObjCreate, not ObjGet.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Scriptomatic is your friend here too. Run a query and you will see that the resulting AutoIt code has a variable $strHost = "localhost". Replace this with the remote computername e.g. "computerremote"

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Scriptomatic is your friend here too. Run a query and you will see that the resulting AutoIt code has a variable $strHost = "localhost". Replace this with the remote computername e.g. "computerremote"

Scriptomatic allows you to select a "WMI Source", which is the target hostname to pull from. This returns a 1 in the namespace list (where it's supposed to return a list of namespaces available from the host). If I just select '1' and select the class from the class list, scriptomatic produces an autoit error and exits. I believe it has something to do with the way our network is setup. If I use my previous code for winmgns as I did for my local machine, instead changing the hostname to another host on the network, it errors. I have to use alternative credentials and domains for each host on the network, which is why I have to use OP method.

@BrewmanNH ahh sorry about that. Didn't know there were two different ways to access an object (I'm clueless when it comes to using objects... I'm learning though.)

$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
ConsoleWrite(@error & @CR)
$objWMIService = $objSWbemLocator.ConnectServer("hostname", "rootcimv2", "domainuser", "password")

Returns

C:Documents and SettingsuserDesktopTestScriptsTEST_DONT_SAVE.au3 (3) : ==> The requested action with this object has failed.:

$objWMIService = $objSWbemLocator.ConnectServer("hostname", "rootcimv2", "domainuser", "password")

$objWMIService = $objSWbemLocator.ConnectServer("hostname", "rootcimv2", "domainuser", "password")^ ERROR

So then I tried

$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator", "hostname", "domainuser", "password")
ConsoleWrite(@error & @CR)
$objWMIService = $objSWbemLocator.ConnectServer("hostname", "rootcimv2", "domainuser", "password")

That returns

C:Documents and Settingsacis4DesktopTestScriptsTEST_DONT_SAVE.au3 (3) : ==> Variable must be of type "Object".:

$objWMIService = $objSWbemLocator.ConnectServer("hostname", "rootcimv2", "domainuser", "password")

$objWMIService = $objSWbemLocator^ ERROR

Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Are you using this to connect to the same computer this is being run on, or a different computer?

Because the code below works on my system, as long as the hostname doesn't equal my computer's name.

$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
ConsoleWrite(@error & @CR)
$objWMIService = $objSWbemLocator.ConnectServer("hostname", "rootcimv2", "domainuser", "password")

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Are you using this to connect to the same computer this is being run on, or a different computer?

Because the code below works on my system, as long as the hostname doesn't equal my computer's name.

$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
ConsoleWrite(@error & @CR)
$objWMIService = $objSWbemLocator.ConnectServer("hostname", "rootcimv2", "domainuser", "password")

Different computer on the same network. It returns "The requested action with this object has failed." when attempting to .ConnectServer.
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Lets say you start Scriptomatic and let it run until it shows "Select a WMI Class" in the WMI Class input field. Select "Win32_BIOS" and click "Run". The following script will be generated:

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", _
                                         $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
For $objItem In $colItems
     $strBiosCharacteristics = $objItem.BiosCharacteristics(0)
     $Output = $Output & "BiosCharacteristics: " & $strBiosCharacteristics & @CRLF
     $strBIOSVersion = $objItem.BIOSVersion(0)
     $Output = $Output & "BIOSVersion: " & $strBIOSVersion & @CRLF
     $Output = $Output & "BuildNumber: " & $objItem.BuildNumber & @CRLF
     $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
     $Output = $Output & "CodeSet: " & $objItem.CodeSet & @CRLF
     $Output = $Output & "CurrentLanguage: " & $objItem.CurrentLanguage & @CRLF
     $Output = $Output & "Description: " & $objItem.Description & @CRLF
     $Output = $Output & "IdentificationCode: " & $objItem.IdentificationCode & @CRLF
     $Output = $Output & "InstallableLanguages: " & $objItem.InstallableLanguages & @CRLF
     $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
     $Output = $Output & "LanguageEdition: " & $objItem.LanguageEdition & @CRLF
     $strListOfLanguages = $objItem.ListOfLanguages(0)
     $Output = $Output & "ListOfLanguages: " & $strListOfLanguages & @CRLF
     $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF
     $Output = $Output & "Name: " & $objItem.Name & @CRLF
     $Output = $Output & "OtherTargetOS: " & $objItem.OtherTargetOS & @CRLF
     $Output = $Output & "PrimaryBIOS: " & $objItem.PrimaryBIOS & @CRLF
     $Output = $Output & "ReleaseDate: " & WMIDateStringToDate($objItem.ReleaseDate) & @CRLF
     $Output = $Output & "SerialNumber: " & $objItem.SerialNumber & @CRLF
     $Output = $Output & "SMBIOSBIOSVersion: " & $objItem.SMBIOSBIOSVersion & @CRLF
     $Output = $Output & "SMBIOSMajorVersion: " & $objItem.SMBIOSMajorVersion & @CRLF
     $Output = $Output & "SMBIOSMinorVersion: " & $objItem.SMBIOSMinorVersion & @CRLF
     $Output = $Output & "SMBIOSPresent: " & $objItem.SMBIOSPresent & @CRLF
     $Output = $Output & "SoftwareElementID: " & $objItem.SoftwareElementID & @CRLF
     $Output = $Output & "SoftwareElementState: " & $objItem.SoftwareElementState & @CRLF
     $Output = $Output & "Status: " & $objItem.Status & @CRLF
     $Output = $Output & "TargetOperatingSystem: " & $objItem.TargetOperatingSystem & @CRLF
     $Output = $Output & "Version: " & $objItem.Version & @CRLF
     if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
     $Output=""
Next
Else
Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_BIOS" )
Endif


Func WMIDateStringToDate($dtmDate)

Return (StringMid($dtmDate, 5, 2) & "/" & _
StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
& " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc
If you copy the script to SciTE and replace
$strComputer = "localhost"
with the name of the remote computer (e.g. "Computer01") you should be able access all WMI classes of the remote computer.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Line 12 returns: 'Variable must be of type "Object"' @ $objWMIService.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Change

$strComputer = "localhost"
to
$strComputer = @Computername
and give it a try.

If it works then it's either a permission problem (try to run the script with #RequireAdmin) or the WMI service does'nt run on the target computer.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I got it working. I was correct in my assumption that I somehow had to pass additional credentials... and I had the command correct before (I'll repost it using the scriptomatic generator output), however I also needed to allow remote WMI Connections in the firewall of the remote machine via CMD:

netsh firewall set service RemoteAdmin enable

This is the revised code to pass alternative credentials to the remote machine using code generated by AutoIt Scriptomatic

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Test.exe
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "RemoteComputer"
$strUser = "admin" ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$strPassword = "password" ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$Output=""
$Output = $Output & "Computer: " & $strComputer & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$objWMIService = $objSWbemLocator.ConnectServer($strComputer, "rootcimv2", $strUser, $strPassword) ; <<<<<<<<<<<<<<<<<<<
;~ $objWMIService = ObjGet("winmgmts:" & $strComputer & "") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Commented Out
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", _
                                         $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
For $objItem In $colItems
     $strBiosCharacteristics = $objItem.BiosCharacteristics(0)
     $Output = $Output & "BiosCharacteristics: " & $strBiosCharacteristics & @CRLF
     $strBIOSVersion = $objItem.BIOSVersion(0)
     $Output = $Output & "BIOSVersion: " & $strBIOSVersion & @CRLF
     $Output = $Output & "BuildNumber: " & $objItem.BuildNumber & @CRLF
     $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
     $Output = $Output & "CodeSet: " & $objItem.CodeSet & @CRLF
     $Output = $Output & "CurrentLanguage: " & $objItem.CurrentLanguage & @CRLF
     $Output = $Output & "Description: " & $objItem.Description & @CRLF
     $Output = $Output & "IdentificationCode: " & $objItem.IdentificationCode & @CRLF
     $Output = $Output & "InstallableLanguages: " & $objItem.InstallableLanguages & @CRLF
     $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
     $Output = $Output & "LanguageEdition: " & $objItem.LanguageEdition & @CRLF
     $strListOfLanguages = $objItem.ListOfLanguages(0)
     $Output = $Output & "ListOfLanguages: " & $strListOfLanguages & @CRLF
     $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF
     $Output = $Output & "Name: " & $objItem.Name & @CRLF
     $Output = $Output & "OtherTargetOS: " & $objItem.OtherTargetOS & @CRLF
     $Output = $Output & "PrimaryBIOS: " & $objItem.PrimaryBIOS & @CRLF
     $Output = $Output & "ReleaseDate: " & WMIDateStringToDate($objItem.ReleaseDate) & @CRLF
     $Output = $Output & "SerialNumber: " & $objItem.SerialNumber & @CRLF
     $Output = $Output & "SMBIOSBIOSVersion: " & $objItem.SMBIOSBIOSVersion & @CRLF
     $Output = $Output & "SMBIOSMajorVersion: " & $objItem.SMBIOSMajorVersion & @CRLF
     $Output = $Output & "SMBIOSMinorVersion: " & $objItem.SMBIOSMinorVersion & @CRLF
     $Output = $Output & "SMBIOSPresent: " & $objItem.SMBIOSPresent & @CRLF
     $Output = $Output & "SoftwareElementID: " & $objItem.SoftwareElementID & @CRLF
     $Output = $Output & "SoftwareElementState: " & $objItem.SoftwareElementState & @CRLF
     $Output = $Output & "Status: " & $objItem.Status & @CRLF
     $Output = $Output & "TargetOperatingSystem: " & $objItem.TargetOperatingSystem & @CRLF
     $Output = $Output & "Version: " & $objItem.Version & @CRLF
     if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
     $Output=""
Next
Else
Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_BIOS" )
Endif


Func WMIDateStringToDate($dtmDate)

Return (StringMid($dtmDate, 5, 2) & "/" & _
StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
& " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Thanks for helping me to figure this out Brew & water. And thanks water for eluding to permissions issues as I searched msdn for security issues related to remote WMI monitoring and found the tidbit on allowing action through the local firewall.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Glad you got it working (with a little help from BrewManNH and me) :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Verified that the above method works remoting FROM XP to XP and Win7

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

This is just what i was looking for, thank you to you all!

There is just one more problem:

If querying the local machine, it only works when leaving user and password blank. I can't even catch the error (pointed to be at the line just above the @error statement; AutoIt will crash silently).

I'd be happy if it'd accept admin credentials on the local machine, as this will be a common condition.

$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIService = $objSWbemLocator.ConnectServer($machine, "rootcimv2", $user, $pwd)
If @error Then
  MsgBox(16, "Error!", "Unable to get properties" & @CRLF & "of machine [ " & $machine & " ]" & @CRLF & "Error code: " & Hex(@error, 8))
  Exit
EndIf
Link to comment
Share on other sites

try this

$objswbemlocator = ObjCreate("WbemScripting.SWbemLocator")
$objswbemservices = $objswbemlocator.ConnectServer($ip, "rootcimv2", $struser, $strpassword, "MS_409", "ntlmdomain:" & $strdomain)
$colitems = $objswbemservices.ExecQuery('SELECT * FROM Win32_GroupUser', 'WQL', 0x30)
......
......
......

without firewall on target...

Edited by SandelPerieanu
Link to comment
Share on other sites

Possible that the ConnectServer method doesn't allow for a loopback connection? Get the WMI service with the following:

;This
$objWMIService = ObjGet("winmgmts:" & $machine & "rootCIMV2")
;Instead of this
;$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
;$objWMIService = $objSWbemLocator.ConnectServer($machine, "rootcimv2", $user, $pwd)
Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

ConnectServer works locally as well, as long as there aren't any credentials or domain involved (adressing local machine by @ComputerName). I just wanted to be able to elevate rights on a local machine where i probably wasn't admin already. Which for a remote machine is the problem that the three of you solved in here beautifully, but there must be another approach to do this locally...

Link to comment
Share on other sites

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394589%28v=vs.85%29.aspx

Use the SWbemLocator.ConnectServer method, or IWbemLocator::ConnectServer in C++, and include the appropriate user name and password. You cannot change credentials when connecting to the local computer. For more information, see Creating a WMI Script and Connecting to WMI on a Remote Computer.

EDIT: So in other words, runas admin. Elevate privileges locally to the script in question and run the command.

Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...