Autohotkey脚本仅在观看时有效

问题描述 投票:2回答:2

我有一个autohotkey脚本,可以自动导入向导GUI。当我RDP进入这个脚本所在的机器时,我可以运行它运行得很漂亮的脚本。该脚本运行10分钟。如果我在计划运行时将RDP加入计算机,我可以看到该脚本运行得很漂亮。

当我退出RDP(或者甚至只是最小化窗口)时,脚本按计划运行并挂起导入向导中的第一个窗口。如果我回到RDP,我会看到那个窗口坐在那里,我看到我的脚本在等待下一个窗口出现时挂起。如果我在打开的窗口上单击“确定”(这正是ahk脚本的功能),那么我的脚本会继续并运行正常。

tldr:我的autohotkey脚本只在我看的时候有效!

这是一些代码......

#NoTrayIcon
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

saexe_file = C:\test.exe
company_file = Z:\ABC.SAI
import_file = D:\test.imp

Run, %saexe_file%

WinWait Simply Accounting Import - Select Company
WinActivate
Send %company_file%{Enter}

; IT HANGS HERE
WinWait Simply Accounting Import - Select File to Import from
WinActivate, Simply Accounting Import - Select File to Import from
Send %import_file%{Enter}

编辑07-12-2013:找到了解决方案:

而不是从RDP断开连接,运行此批处理文件...

for / f“usebackq skip = 1 tokens = 3”%% i in(query user %USERNAME%)do%winder%\ system32 \ tscon.exe %% i / dest:console

windows autohotkey remote-desktop
2个回答
1
投票

这本脚本本身不是问题。

当您在RDP会话中工作时,您的帐户已登录,并且该脚本在您的帐户下运行。

要在“不看”时运行它,您必须获取系统帐户才能操作文件的执行。

尝试使用Windows任务计划程序运行脚本,如果要求,请使用系统帐户。


0
投票

如上所述,关闭或断开RDP会话将不起作用。

而是从命令窗口执行此命令(如果需要,可以将其放在bat文件中):

tscon RDP-Tcp#0 /dest:console

#字符后面的数字是您当前的RDP会话#。您可以在任务管理器/用户选项卡中找到它

这会导致您的RDP会话切换到“控制台”模式,并且GUI将继续在此模式下运行

为我工作!

© www.soinside.com 2019 - 2024. All rights reserved.