tags:

views:

3213

answers:

4

I'm using AutoIt to start and automate some clicks on special GUI application. I need to activate the script each hour.

Will AutoIt script work when used as a service?

UPDATE: Referring to the first answer. The script will be run as a service (not scheduled task) because don't want to use task scheduler on server.

+1  A: 

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.

Simon Svensson
A: 

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)

James Brooks
+3  A: 

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.

Copas
A: 

Why not to use Scheduled Tasks on Servers?