#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; Example of using service UDF to make an exe possibly runeed as a service
; By Arcker
; 10/09/2008
#include<Service.au3>
$sServiceName = "Autoit_Service" ;定义服务名称
If $cmdline[0] > 0 Then ;检查启动参数
Switch $cmdline[1]
Case "install", "-i", "/i" ;install -i 即安装服务
InstallService()
Case "remove", "-u", "/u", "uninstall" ;remove -u 则删除服务
RemoveService()
Case Else ;若启动参数为空则在控制台显示帮助
ConsoleWrite(" - - - Help - - - " & @crlf)
ConsoleWrite("params : " & @crlf)
ConsoleWrite(" -i : install service" & @crlf)
ConsoleWrite(" -u : remove service" & @crlf)
ConsoleWrite(" - - - - - - - - " & @crlf)
Exit
;start service.
EndSwitch
EndIf
_Service_init($sServiceName) ;设置服务
func main()
while 1
;doing what you want here 此处加入你想循环执行的代码
;msgbox(0,"","ok")
Sleep(1000)
WEnd
EndFunc
Func InstallService()
ConsoleWrite("Installing service, please wait" & @CRLF)
_Service_Create("", $sServiceName, "Autoit Service Test", '"' & @ScriptFullPath & '"')
If @error Then
ConsoleWrite("Problem installing service, Error number is " & @error & @CRLF & " message : " & _WinAPI_GetLastErrorMessage())
Else
ConsoleWrite("Installation of service successful")
EndIf
Exit
EndFunc ;==>InstallService
Func RemoveService()
_StopService("", $sServiceName)
_DeleteService("", $sServiceName)
if not @error then ConsoleWrite("service removed successfully" & @crlf)
Exit
EndFunc ;==>RemoveService
作者的示例,帮你加了一下注释
[ 本帖最后由 ceoguang 于 2009-1-19 16:54 编辑 ] |