作为服务执行的 AutoIt 脚本是不是适用于 GUI 操作?

Posted

技术标签:

【中文标题】作为服务执行的 AutoIt 脚本是不是适用于 GUI 操作?【英文标题】:Do AutoIt scripts, executed as service, function for GUI actions?作为服务执行的 AutoIt 脚本是否适用于 GUI 操作? 【发布时间】:2010-10-11 17:31:34 【问题描述】:

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

AutoIt 脚本(在 GUI 上执行操作)在用作服务时会起作用吗?该脚本将作为服务运行(不是计划任务)。

【问题讨论】:

【参考方案1】:

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

【讨论】:

【参考方案2】:

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

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

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[ServiceName]", "Type", "REG_DWORD", 0x110)

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

【讨论】:

【参考方案3】:

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

【讨论】:

以上是关于作为服务执行的 AutoIt 脚本是不是适用于 GUI 操作?的主要内容,如果未能解决你的问题,请参考以下文章

运维开发windows下的自动化脚本语言autoit

Selenium怎么优化AutoIT文件上传?

适用于 G Suite 的 Android 管理 API

selenium+java利用AutoIT实现文件上传

autoit中如何把指定内容复制到剪贴板?

NSG 是不是适用于子网的服务端点