【问题标题】:how to write AutoIt script on locked terminal如何在锁定的终端上编写 AutoIt 脚本
【发布时间】:2015-03-27 10:45:41
【问题描述】:

我有一个问题,我使用 Windows 任务调度程序运行 autoit (.au3) 脚本,以将交互式命令发送到第二个程序 PuTTY,该程序用于通过串行端口 (RS232) 将命令发送到电气设备接受腻子命令。

我从其他线程中读到的问题是,当终端被锁定时,GUI 命令不会运行,并且由于安全原因,我不能让它一直运行在登录状态。

有没有一种方法可以在不使用“键盘/鼠标”命令的情况下让 putty 工作? 这是一个非常简单的脚本。

run ("C:\Users\Public\Downloads\putty\putty.exe")
sleep(1000)
send ("{TAB 4}")//all these commands select the saved configuration for the com port, and open the PuTTY console
send ("{DOWN 2}")
send ("{TAB 1}")
send ("{ENTER}")
sleep(600)
send ("{TAB 4}")
send ("{ENTER}")
sleep(600)
send("{ASC 83}")//this sends the five characters "START" while in the PuTTY console
send("{ASC 84}")
send("{ASC 65}")
send("{ASC 82}")
send("{ASC 84}")
send("{ENTER}")
sleep(3000)
winclose("COM3 - PuTTY")//closes PuTTY.exe
sleep(2000)
send("{ENTER}")

我尝试过使用 ControlSend,但这根本不起作用。

这是我用来让任务调度程序运行 putty.exe 而不是打开它的命令:

cmd /c start "" "C:\Users\Bobby\Documents\runputty.au3"

【问题讨论】:

  • 您是否考虑过编写一个程序直接通过 RS232 进行通信,而不是使用 AutoIt 来自动化 PuTTY?即使计算机被锁定,这样的控制台应用程序也能运行。
  • 我试过了,但是当我成功打开端口并发送命令时,程序失败了,因为我不知道如何对设备进行“握手/流量控制”,这就是我求助的原因使用第三方 progs
  • 那么,恐怕你可能被卡住了。毕竟,您可能必须以编程方式执行此操作,并且只需了解握手。

标签: task scheduler putty autoit


【解决方案1】:

我使用此代码(第一次您必须手动登录并确认服务器指纹):

Func _runSshCommand($plinkUser, $plinkHost, $command, $password = "", $timeoutInMs = 0)
 $plinkFile = "c:\putty\plink.exe"
 $runThis = @ComSpec & " /c " & $plinkFile & " -batch " & $plinkUser & "@" & $plinkHost
 If $password <> "" Then $runThis &= " -pw " & $password
 $runThis &= " " & $command
 $plinkHandle = Run($runThis, "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
 $plinkFeedback = ""
 $waitForOutputStartTime = _Timer_Init()
 Do
  Sleep(10)
  $plinkFeedback &= StdoutRead($plinkHandle)
  $stdoutReadError = @error
 Until $stdoutReadError Or ($timeoutInMs And _Timer_Diff($waitForOutputStartTime) > $timeoutInMs)
 If ProcessExists("plink.exe") Then ProcessClose("plink.exe")
 If $stdoutReadError <> 0 Then Return $plinkFeedback
 EndFunc   ;==>_runSshCommand

详情请访问此主题AutoIt Plink Wrapper。 祝你今天过得愉快! :)

【讨论】:

    【解决方案2】:

    我已经解决了我的问题:在我重新安装了 prolific 串口线驱动程序,然后重新配置了我的 controlsend 语句后,它工作了。

    【讨论】:

      猜你喜欢
      • 2018-11-06
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-14
      • 1970-01-01
      • 2014-10-08
      • 2018-12-09
      相关资源
      最近更新 更多