【问题标题】:Run AutoIt on remote machine using psexec使用 psexec 在远程机器上运行 AutoIt
【发布时间】:2014-10-07 12:58:32
【问题描述】:

我正在尝试在远程机器上运行 AutoIt 脚本。

psexec.exe -accepteula \\remotemachine -u admin -p password "C:\Program Files\AutoIt3\AutoIt3.exe" "C:\Users\admin\runNotepad.au3"

我正在尝试从脚本中打开记事本并在其中写一些东西。我也在从脚本中写一些日志。虽然我可以看到日志,但我看不到屏幕上发生的任何事情。

我尝试使用参数-i 0 打开一个交互式屏幕,这与在本地计算机上运行脚本不同。还有其他方法吗?

【问题讨论】:

    标签: python autoit psexec


    【解决方案1】:

    我终于弄明白了。我们应该首先找出该用户的远程机器的登录会话 ID。我首先使用 psexec 运行 qwinsta 命令来检查会话 ID

    psexec \\remote -u admin -p password  qwinsta
    

    这给了我所有会话的列表。签出具有与之关联的用户名的活动会话。 就我而言,它是 2。

    然后我运行这个命令,会话 ID 为 2

    psexec.exe -i 2 -accepteula \\remotemachine -u admin -p password "C:\Program Files\AutoIt3\AutoIt3.exe" "C:\Users\admin\runNotepad.au3"
    

    【讨论】:

      【解决方案2】:

      这行得通吗?

      #include <Date.au3>
      #include <File.au3>
      
      
      _LaunchProgramOnRemoteComputer("192.168.50.0", "TEST-PC", "usertest", "passtest", "D:\programToExecute.exe", "", True, "15")
      
      
      ; #FUNCTION# ====================================================================================================================
      ; Name...........: _LaunchProgramOnRemoteComputer
      ; Description ...: Copy and execute a program on remote computer.
      ;
      ; Syntax.........: _LaunchProgramOnRemoteComputer($ipaddress, $domain, $username, $password, $program[, $parameters = ""[, $show = True[, $timeout = "15"]]])
      ;
      ; Parameters ....: $ipadress    - IP Address of the remote computer.
      ;                 $domain     - Active Directory domain name or Remote computer name.
      ;                 $username - Username of the user who execute the program on the remote computer.
      ;                 $password - Password of the user who execute the program on the remote computer.
      ;                 $program      - Local path of the program to execute.
      ;                 $parameters  - Parameters of the program.
      ;                 $show     - Display the interaction with the remote Desktop (True or False).
      ;                 $timeout   - Timeout in seconds (like "20").
      ;
      ; Return values .: Success    - Returns the return code of the program executed.
      ;                 Failure     - 0  and sets @ERROR
      ;                                            1 : Timeout.
      ;                                            2 : PsExec service failed to start on the remote computer.
      ;                                            3 : The program could not be executed.
      ;
      ; Author ........: Jeremy Guillot
      ; Modified.......:
      ; Remarks .......:
      ; Related .......:
      ; Link ..........:
      ; Example .......:
      ; ===============================================================================================================================
      Func _LaunchProgramOnRemoteComputer($ipaddress, $domain, $username, $password, $program, $parameters = "", $show = True, $timeout = "15")
      
          ; We decompose the path of the program.
          Local $sProgramDrive, $sProgramDir, $sProgramFName, $sProgramExt
          _PathSplit($program, $sProgramDrive, $sProgramDir, $sProgramFName, $sProgramExt)
      
          ; Delete the file on the remote machine.
          RunAsWait($username, $domain, $password, 2, @ComSpec & ' /c del /F \\"' & $ipaddress & "\c$\" & $sProgramFName & $sProgramExt, "", @SW_HIDE)
      
          ; Copy the program on sharing 'c$' on the remote machine.
          RunAsWait($username, $domain, $password, 2, @ComSpec & ' /c copy /Y "' & $program & '" \\"' & $ipaddress & "\c$\" & $sProgramFName & $sProgramExt, "", @SW_HIDE)
      
          ; Parameters of the program.
          If $parameters <> "" Then $parameters = " " & $parameters
      
          ; Display the interaction with the remote Desktop.
          If $show Then
              $show = " -i"
          Else
              $show = ""
          EndIf
      
          ; Program execution.
          Local $iStdoutg = Run(@comspec & " /c PsExec \\" & $ipaddress & " -u " & $domain & "\" & $username & " -p " & $password & $show & " -h -n " & $timeout & " C:\" & $sProgramFName & $sProgramExt & $parameters, @ScriptDir & "\Tools\PsTools\", @SW_HIDE, 6)
          Local $sTimeoutBegin = _NowCalc()
          Local $sCommandResult = ""
          Local $sCurrentLine = ""
          While True
              If _DateDiff("s", $sTimeoutBegin, _NowCalc()) > $timeout Then
                  ProcessClose("PsExec.exe")
                  ProcessClose("PSEXESVC.exe")
                  Return SetError(1, 0, 0)
              EndIf
              $sCurrentLine = StderrRead($iStdoutg)
              If @error Then ExitLoop
              If $sCurrentLine <> "" Then
                  $sCommandResult = $sCommandResult & @CRLF & $sCurrentLine
              EndIf
          WEnd
          ;If $sCommandResult <> "" Then ConsoleWrite($sCommandResult & @CRLF)
      
          ; Closing the PsExec process in case they would not shut.
          ProcessClose("PsExec.exe")
          ProcessClose("PSEXESVC.exe")
      
          ; Remove the program on the remote machine.
          RunAsWait($username, $domain, $password, 2, @ComSpec & ' /c del /F \\"' & $ipaddress & "\c$\" & $sProgramFName & $sProgramExt, "", @SW_HIDE)
      
          ; Error handling.
          Local $bServiceStarted = False
          Local $bCommandExecuted = False
          Local $bCommandFinished = False
          If StringInStr($sCommandResult, "Connecting with PsExec service on") And Not $bServiceStarted Then $bServiceStarted = True
          If StringInStr($sCommandResult, "Starting " & $program & " on") And Not $bCommandExecuted Then $bCommandExecuted = True
          If StringInStr($sCommandResult, " exited on " & $ipaddress & " with error code") And Not $bCommandFinished Then $bCommandFinished = True
      
          If $bCommandFinished Then
              ; We get the return code of the program.
              $sCommandResult = StringStripCR(StringStripWS(StringStripWS($sCommandResult, 1), 2))
              Local $sCommandResultCodePosition = StringInStr($sCommandResult, "with error code ")
              $sCommandResult = StringTrimLeft($sCommandResult, $sCommandResultCodePosition)
              $sCommandResult = StringTrimLeft($sCommandResult, 15)
              $sCommandResult = StringTrimRight($sCommandResult, 1)
          Else
               If Not $bServiceStarted Then Return SetError(2, 0, 0)
               If Not $bCommandExecuted Then Return SetError(3, 0, 0)
          EndIf
      
           Return SetError(0, 0, $sCommandResult)
      
      EndFunc
      

      【讨论】:

      • 这本质上是在问题中运行相同的命令,但来自 autoit。对我不起作用。它对你有用吗?
      【解决方案3】:

      您使用的是什么操作系统?如果是 Vista 或更高版本,您是否尝试过参数 -i 1 ?我相信会话 0 是为 Windows 服务保留的:http://blogs.technet.com/b/askperf/archive/2007/04/27/application-compatibility-session-0-isolation.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多