Jump to content
Sign in to follow this  
4Eyes

WMI process launch issues

Recommended Posts

4Eyes

Folks,

I wish to have a remote pc launch a program via WMI that resides on a network. I can launch a program on the remote pc via WMI, but only if that program is local, not on a network. Tried mapped drive letter, share etc. Example code below.

Global $strComputer = "mikes-nb", $strUsername = "", $strPassword = ""

; From remote pc this works \\mikespc\sharename\DebugAgent.exe
; From remote pc this does not work \\192.168.1.102\sharename\DebugAgent.exe                        ; Fine... doesn't work with IP address spec'ing pc

;RemoteExecute("\\mikespc\c$\AutoITStuff\\agents\DebugAgent.exe")                                   ; This doesn't work - using the full path
;RemoteExecute("\\share\DebugAgent.exe")                                                            ; This doesn't work - using a share
;RemoteExecute("p:\DebugAgent.exe")                                                                 ; This doesn't work - using a drive letter mapped to a share
;RemoteExecute("cmd.exe /c start p:\DebugAgent.exe")                                                ; This launches a process named cmd.exe but there is no window.
;RemoteExecute("cmd.exe /c p:\DebugAgent.exe")                                                      ; This launches a process named cmd.exe but there is no window.

;RemoteExecute("c:\windows\system32\calc.exe")                                                      ; This works - executes on local pc
;RemoteExecute("cmd.exe /c dir c:\windows\system32\calc.exe")                                       ; This does nothing
;RemoteExecute("cmd.exe /c start c:\windows\system32\calc.exe")                                     ; This launches a process named calc.exe but there is no window

; DebugAgent is simply a MsgBox. Thinking that maybe that's 'too interactive' I tried just Sleep(10000) to give long enought to see if anything happens, but no.

;*****************************

; This func runs the passed prog on the remote or local pc spec'ed by $strComputer. Will NOT show gui if remote, but will on local pc.

Func RemoteExecute($strProgToRun)

    Local $objWMIService, $objProcess, $objProgram

    $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
    If Not IsObj($objSWbemLocator) Then
        MsgBox(0, "Error", "Error: failed to create $objSWbemLocator")
        Exit
    EndIf

    $objWMI = $objSWbemLocator.ConnectServer($strComputer, "root\cimv2", $strUsername, $strPassword)    ; This works for remote pc if pass actual credentials and works for local if pass null credentials
    If Not IsObj($objWMI) Then
        MsgBox(0, "Error", "Error: failed to create $objWMI")
        Exit
    EndIf

    $objWMI.Security_.ImpersonationLevel = 3

    $objProcess = $objWMI.Get("Win32_Process")

    $objProgram = $objProcess.Methods_("Create").InParameters.SpawnInstance_
    $objProgram.CommandLine = $strProgToRun

    $objWMI.ExecMethod("Win32_Process", "Create", $objProgram)                                          ; Execute the program now at the command line.

EndFunc     ; End of Func RemoteExecute()

;*****************************

I've found a number of different techniques in both VBS and AutoIT to launch a program on a remote pc but none work if that program is on a network. I truly do NOT understand.

Maybe it's my setup, but I think not. Main pc is XP Pro SP3, remote is Win7 with UAC off. Admin on both.

Could someone with 2 or more pc's please try this and advise?

Alternatively, if there's a technique to launch an app on a remote pc not using WMI, but using AutoIT only then please advise. I do NOT want to use PSExec or have to install something on the remote pc.

Thanks,

4Eyes

Edited by 4Eyes

Share this post


Link to post
Share on other sites
kontdracula

I have tested on remote machines , It is working without any problems...

Share this post


Link to post
Share on other sites
JLogan3o13

What is the error you are receiving when you run your script? Otherwise we're just guessing.


√-1 2^3 ∑ π, and it was delicious!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.