Jump to content

Flummoxed by Objects


Graywalker
 Share

Recommended Posts

I'm trying to figure out how to use objects in AutoIT. More specifically, how to run a program on a remote computer using my old tried and true methods from VBScript....

Set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPCName & "\root\cimv2")
        Set objProcess = objWMIService.Get("Win32_Process")
        Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
        objProgram.CommandLine = Replace(strUninstall,"/I","/X") & " /qn"
        Wscript.echo Now & " Uninstalling " & strDisplayName & " using " & objProgram.CommandLine
        LogFile.WriteLine("<br>Uninstalling using <b>" & objProgram.CommandLine & "</b> <br>")
        Set strShell = objWMIService.ExecMethod("Win32_Process","Create",objProgram)

or such...

$oWMIService = ObjCreate("winmgmts:{impersonatonLevel=impersonate}!\\" & $sComputer & "\root\cimv2")
    $oProcess = $oWMIService.Get("Win32_Process")
    $oProgram = $oProcess.Methods_("Create").InParameters.SpawnInstance_
    $oProgram.CommandLine = "cmd dothisthing.exe"
    $strShell = $oWMIService.ExecMethod("Win32_Process","Create", $oProgram)

Isn't working.... getting a "Variable must be 'object' type" error on the $oProcess line. People have been coming up with all kinds of weird problems and scripting requests all week, brain is mush and its Friday.... What am I missing?

Link to comment
Share on other sites

I'm trying to figure out how to use objects in AutoIT. More specifically, how to run a program on a remote computer using my old tried and true methods from VBScript....

Set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPCName & "\root\cimv2")
        Set objProcess = objWMIService.Get("Win32_Process")
        Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
        objProgram.CommandLine = Replace(strUninstall,"/I","/X") & " /qn"
        Wscript.echo Now & " Uninstalling " & strDisplayName & " using " & objProgram.CommandLine
        LogFile.WriteLine("<br>Uninstalling using <b>" & objProgram.CommandLine & "</b> <br>")
        Set strShell = objWMIService.ExecMethod("Win32_Process","Create",objProgram)

or such...

$oWMIService = ObjCreate("winmgmts:{impersonatonLevel=impersonate}!\\" & $sComputer & "\root\cimv2")
    $oProcess = $oWMIService.Get("Win32_Process")
    $oProgram = $oProcess.Methods_("Create").InParameters.SpawnInstance_
    $oProgram.CommandLine = "cmd dothisthing.exe"
    $strShell = $oWMIService.ExecMethod("Win32_Process","Create", $oProgram)

Isn't working.... getting a "Variable must be 'object' type" error on the $oProcess line. People have been coming up with all kinds of weird problems and scripting requests all week, brain is mush and its Friday.... What am I missing?

Your VBS uses GetObject, but your AutoIt uses ObjCreate? Did you try ObjGet()?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

$oWMIService = ObjCreate("winmgmts:.....

needs to be

$oWMIService = ObjGet("winmgmts:.....

i believe

edit: he he same time as PsaltyDS. :)

Edited by spudw2k
Spoiler

Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder
Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array
Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc
Cool Stuff: AutoItObject UDF â—Š Extract Icon From Proc â—Š GuiCtrlFontRotate â—Š Hex Edit Funcs â—Š Run binary â—Š Service_UDF

 

Link to comment
Share on other sites

Your VBS uses GetObject, but your AutoIt uses ObjCreate? Did you try ObjGet()?

:)

Yeah, ObjGet() was the first thing I tried, tried the Create when I kept getting :

Variable must be of type "Object".:
$oProcess = $oWMIService.Get("Win32_Process")
$oProcess = $oWMIService^ ERROR

in the debug console (using Tools - Go in SciTE). Also getting the "variable must be of type "object" when running the script.

Link to comment
Share on other sites

So, then this advice above turned up nothing for you? ... curious.

He can't call ExecMethod until he gets a valid reference in $oWMIService first, which is already failing. But I can see that would be cleaner thereafter.

Try it with some error handling. This works fine for me:

$sComputer = @ComputerName
$oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sComputer & "\root\cimv2")
If IsObj($oWMIService) Then
    ConsoleWrite("Debug: Object retrieved: " & ObjName($oWMIService) & @LF)
    $oProcess = $oWMIService.Get('Win32_Process')
    If IsObj($oProcess) Then
        ConsoleWrite("Debug: Got WMI object and Win32_Process object: " & ObjName($oProcess) & @LF)
    Else
        ConsoleWrite("Debug: Got WMI object, but failed to get Win32_Process object." & @LF)
    EndIf
Else
    ConsoleWrite("Debug: Failed to get WMI object." & @LF)
EndIf

Output:

>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "C:\Temp\Test1.au3"    
Debug: Object retrieved: ISWbemServicesEx
Debug: Got WMI object and Win32_Process object: ISWbemObjectEx
+>17:00:43 AutoIT3.exe ended.rc:0

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...