Jump to content

Service Scripting


Recommended Posts

To run a compiled AutoIt script as a service, you can use Instsrv.exe and Srvany.exe from Microsoft.

A UDF below may help to setup the service. Have Instsrv.exe and Srvany.exe in System32 directory.

Func _SrvAny($service, $fullpath, $hidden = 0)
; Adds a program, as a windows service.
; Requires $instsrv and $srvany to be assigned, full paths.
; e.g. _SrvAny ( 'ServiceName', 'FullPath_to_the_program' )
    Local $instsrv = @WindowsDir & '\System32\Instsrv.exe'
    Local $srvany = @WindowsDir & '\System32\SrvAny.exe'
    If FileExists($instsrv) And FileExists($srvany) Then
        RunWait($instsrv & ' ' & $service & ' "' & $srvany & '"', '', @SW_HIDE)
        Local $key = 'HKLM\SYSTEM\CurrentControlSet\Services\' & $service
        If RegRead($key, 'DisplayName') Then
            If $hidden Then RegWrite($key & '\Parameters', 'AppParameters', 'Reg_sz', '/hidden')
            Return RegWrite($key & '\Parameters', 'Application', 'Reg_sz', $fullpath)
        EndIf
    EndIf
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...