Jump to content

start remote exe


Recommended Posts

Hi at all,

I tried a long time to start an exe at a remote machine. I know the name and ip of this machine, the username and his password and the machine is connect via LAN with my computer. The problem is I dont want to use psexec for this.

My first attempt was with NamedPipes, but there was one problem left. I created a message pipe at the remote machine and checked with WaitNamedPipe if the Pipe is available. So I have the handle to the server side end and the name of the pipe. But to write in I need the handle to the clientend of the pipe, because the remote machine is the pipeserver and my computer is the pipeclient.

I searched for function which translate the pipename to the pipehandle, but cannot find such a function in the autoit-libraries. Maybe anyone can push me in the right direction or give me the right link (by searching pipe, handle or remote in the forum I wasn´t able to find a simmilar problem).

It´s also possible, that there is an easier way to start a remote proccess without using neither psexec not namedpipes.

At any help I would be appreciated. Thanks.

Link to comment
Share on other sites

Does PsExec even at least work for your purposes? It doesn't get much easier than PsExec and in case it doesn't work there's a good chance a lot of other similar utilities won't work either.

From this link: http://www.autoitscript.com/forum/index.php?showtopic=37289

There's also BeyondExec from BeyondLogic. Will this work or are you trying not to use any external applications whatsoever?

Here are some attempts in another post: http://www.autoitscript.com/forum/index.php?showtopic=44913

Link to comment
Share on other sites

Thank you,

I´ll try the links.

psexec works and also beyondexec was succesfull, but like you said I wan´t to do it only with autoit and without external applications.

I hope this is possible, because I don´t really need the whole features of psexec.

Ok I´ll try this, thank you again.

Edited by Foertel
Link to comment
Share on other sites

So I tested the tips you gave me. I think the post of lordofthestrings fits best to my problem. Thanks for the links again.

Now I´ve got an error, which I didn´t understand yet. In some cases $objWMIService isn´t an object after the ObjGet-Function. So I added if-else to check.

func RemoteExecute($strComputer, $CommandLine)
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") 
If IsObj($objWMIService) == 0 Then                                                                      ;Check if $objWMISevice is an object   (NEW)
   MsgBox(0,'IsObj','$objWMIService must be of type "Object"')
Else
   $objShare = $objWMIService.Get("Win32_Process")
   $objInParam = $objShare.Methods_("Create").inParameters.SpawnInstance_()
   $objInParam.Properties_.Item("CommandLine") =  $CommandLine
   $objOutParams = $objWMIService.ExecMethod("Win32_Process", "Create", $objInParam)
   $PID = $objOutParams.ProcessId 
   $ReturnValue = $objOutParams.ReturnValue
   Switch $ReturnValue
        Case 0
            msgbox(0, "RunRemote","The remote command completed successfully")
        Case 2
            msgbox(0, "RunRemote","Answer from Remote Computer: Access denied")
        Case 3
            msgbox(0, "RunRemote","Insufficient privilege to launch remote command")
        Case 8
            msgbox(0, "RunRemote","Unknown failure")
        Case 9
            msgbox(0, "RunRemote","Path not found")
        Case 21
            msgbox(0, "RunRemote","Invalid parameter passed to script: " & @CRLF & _
                        "$strComputer: " & $strComputer & @CRLF & _
                        "$CommandLine: " & $CommandLine)
        Case Else
            msgbox(0, "RunRemote","Unknown error" & @CRLF & _
                        "ResultCode: " & $ReturnValue)
    EndSwitch
EndIf
EndFunc
$objWMIService is an object when I execute the script with my local computername and with only one of my remote machines. By testing the script with all other remote machines the ObjGet-Function fails and the MsgBox appears. Is it possible that there is a file missing (? CIMV2 ?) on the targetsystems or what else could be the problem?
Link to comment
Share on other sites

Link to comment
Share on other sites

Does the account you are using for remote WMI calls have Admin rights on those machines?

Yes I have Admin rights and the account I use has the same username and password like the user, who is loged on the running machines I want to have access to.

Link to comment
Share on other sites

Hi,

let me just summarize, what I´ve raed and tried so far:

I also used the advanced function of lordofthestring. At the marked line I got following error:

==> The requested action with this object has failed.:

$Service = $Locator.ConnectServer($strComputer,"root/cimv2",$User,$Password)

$Service = $Locator.ConnectServer($strComputer,"root/cimv2",$User,$Password)^ ERROR

func RemoteExecuteAdvanced()
    global $Hostname,$Application,$WorkingDirectory,$User,$Password
    $Locator = ObjCreate("WbemScripting.SWbemLocator")
    $Service = $Locator.ConnectServer($Hostname,"root/cimv2",$User,$Password)                               ;here is the error
    $Security = $Service.Security_
    $Security.ImpersonationLevel = 3
    $Class = $Service.Get("Win32_Process")
    If $WorkingDirectory == "" then
        $Result = $Class.Create($Application)  ;no working directory specified
    Else
        $Result = $Class.Create($Application,$WorkingDirectory)
    EndIf
;   $Class.close
;   $Security.close
;   $Service.close
;   $Locator.close
    Switch $Result
        Case 0
            msgbox(0, "RunRemote","The remote command completed successfully")
        Case 2
            msgbox(0, "RunRemote","Answer from Remote Computer: Access denied")
        Case 3
            msgbox(0, "RunRemote","Insufficient privilege to launch remote command")
        Case 8
            msgbox(0, "RunRemote","Unknown failure")
        Case 9
            msgbox(0, "RunRemote","Path not found")
        Case 21
            msgbox(0, "RunRemote","Invalid parameter passed to script: " & @CRLF & _
                        "$Hostname: " &         $Hostname &         @CRLF & _
                        "$Application: " &      $Application &      @CRLF & _
                        "$WorkingDirectory: " & $WorkingDirectory & @CRLF & _
                        "$User: " &             $User &             @CRLF & _
                        "$Password: " &         $Password)
        Case Else
            msgbox(0, "RunRemote","Unknown error" & @CRLF & _
                        "ResultCode: " & $Result)
    EndSwitch
EndFunc

Because this is also the line with the access to the remote "root/simv2" I raed some articels about wmi security at msdn-homepage. I tried some settings, which really seems to solve my problem. Now at one remote machine all users (also ANONYMOUS LOGON) have full rigths to launch remote processes, but the result the executing my script is the same.

There are also some forums which discuss the same errormessage. It´s always the way, that some users have the problem and the others havn´t, but no one could explain how to solve it.

I would really appreciate if anyone could push me in the right direction.

__EDIT__

I forgot to mention: I also checked, that the wmi-service is running correctly at the remote machine.

Edited by Foertel
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...