作为服务执行的 AutoIt 脚本是否可以用于 GUI 操作?

发布于 2024-07-14 19:33:49 字数 190 浏览 9 评论 0原文

我正在使用 AutoIt 脚本来启动和自动化 GUI 应用程序。 我需要每小时激活该脚本。

AutoIt 脚本(在 GUI 上执行操作)作为服务使用时是否有效? 该脚本将作为服务运行(不是计划任务)。

I'm using an AutoIt script to start and automate a GUI application. I need to activate the script each hour.

Will AutoIt scripts (which perform actions on a GUI) work when used as a service? The script will be run as a service (not scheduled task).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阳光①夏 2024-07-21 19:33:49

您可以轻松地将 autoit 脚本作为服务运行 使用 autoit 论坛的 archer 编写的 service.au3。 不幸或幸运,因为这是一项安全措施。 服务需要独立于当前用户会话启动(登录之前)。 它无法从那里访问发送 API 以进行当前用户会话的输入操作。 听起来确实更像您需要计划任务而不是服务。

You can easily make an autoit script run as a service using service.au3 written by archer of the autoit forums. Unfortunately or fortunately since it is a security measure. A service needs to start independent of the current user session (before login). It cant access send APIs for input manipulation of the current user session from there. It does sound much more like you need a scheduled task and not a service.

惯饮孤独 2024-07-21 19:33:49

如上所述,您正在寻找计划任务。 要将脚本作为服务运行,请阅读以下内容:

第四季度。 如何将我的脚本作为服务运行?
这也是一个有多种答案的问题,没有一个是唯一的方法。 首先要问自己的问题是,您是否希望在自己的计算机之外的其他计算机上安装该服务。

A1. If you only wish to install the service on your own computer, The easiest way to do this is to use Pirmasoft RunAsSvc. This program makes services easy to install and easy to remove when necessary.
A2. If you wish to make the service available to anyone running your script, you can use SRVANY.EXE and ServiceControl.au3. You can then use this code to install your script as a service:
    #include "ServiceControl.au3"
    $servicename = "MyServiceName"
    _CreateService("", $servicename, "My AutoIt Script", "C:\Path_to_srvany.exe", "LocalSystem", "", 0x110)
    RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\" & $servicename & "\Parameters", "Application", "REG_SZ", @ScriptFullPath)

or use the following code to delete this service:
    #include "ServiceControl.au3"
    $servicename = "MyServiceName"
    _DeleteService("", $servicename)

将 AutoIt 设置为一项服务有一个注意事项。 如果该服务不是使用上述代码安装的,则它必须具有“允许服务与桌面交互”设置,否则自动化功能(例如 Control* 或 Win* 功能)将无法运行。 为了确保服务确实具有此设置,请使用以下代码:
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services[服务名称]", "类型", "REG_DWORD", 0x110)

取自 AutoIt 论坛上的常见问题解答主题。 www.autoitscript.com/forum/index.php?showtopic=37289)

As mentioned above, a scheduled task is what you're looking for. To run a script as a service read this:

Q4. How can I run my script as a service?
This is also a question with multiple answers, and none of them are the only way to do it. The first question to ask yourself is whether or not you wish to install the service on other computers besides your own.

A1. If you only wish to install the service on your own computer, The easiest way to do this is to use Pirmasoft RunAsSvc. This program makes services easy to install and easy to remove when necessary.
A2. If you wish to make the service available to anyone running your script, you can use SRVANY.EXE and ServiceControl.au3. You can then use this code to install your script as a service:
    #include "ServiceControl.au3"
    $servicename = "MyServiceName"
    _CreateService("", $servicename, "My AutoIt Script", "C:\Path_to_srvany.exe", "LocalSystem", "", 0x110)
    RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\" & $servicename & "\Parameters", "Application", "REG_SZ", @ScriptFullPath)

or use the following code to delete this service:
    #include "ServiceControl.au3"
    $servicename = "MyServiceName"
    _DeleteService("", $servicename)

There is one caveat to setting up AutoIt as a service. If the service is not installed using the above code, it must have the "allow service to interact with the desktop" setting or else automation functions such as Control* or Win* functions will not function. To assure the service does indeed have this setting, use the following code:
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services[ServiceName]", "Type", "REG_DWORD", 0x110)

Taken from the FAQ topic on the AutoIt Forums. www.autoitscript.com/forum/index.php?showtopic=37289)

请恋爱 2024-07-21 19:33:49

听起来您想使用计划任务而不是服务。 计划任务可以在您登录时每小时执行一次,并且还应该能够与您的桌面进行交互。 请记住,如果您使用启用了用户帐户控制的 Vista/Windows Server 2008,则以普通用户身份运行的任务无法与提升的程序交互(发送输入)。

It sounds like you're want to use a scheduled task instead of a service. Scheduled tasks can execute every hour, while you're logged in, and should also be able to interact with your desktop. Just remember that a task run as a normal user can not interact (send input) to a elevated program if you're using Vista/Windows Server 2008 with User Account Control enabled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文