#include #include #include "services.au3" #NoTrayIcon #RequireAdmin Opt("mustdeclarevars",1) Dim $sServiceName = "MyService" Dim $hTimer = TimerInit() ;Service installation and removing with cli arguments part logprint("*** "& $sServiceName & " Service Started") If $cmdline[0] > 0 Then Switch $cmdline[1] Case "install", "-i", "/i" _Service_Create($sServiceName, $sServiceName, $SERVICE_WIN32_OWN_PROCESS, $SERVICE_DEMAND_START, $SERVICE_ERROR_SEVERE, '"' & @ScriptFullPath & '"') If @error Then logprint("Service InstallService("&$sServiceName&"): Problem installing service, Error number is " & @error & " - " & _WinAPI_GetLastErrorMessage()) Else logprint("Service InstallService("&$sServiceName&"): Installation of service successful") EndIf Exit Case "remove", "-u", "/u", "uninstall" _Service_Stop($sServiceName) _Service_Delete($sServiceName) If @error Then logprint("Service RemoveService("&$sServiceName&"): Problem removing service, Error number is " & @error & " - " & _WinAPI_GetLastErrorMessage()) Else logprint("Service RemoveService("&$sServiceName&"): Removing of service successful") EndIf Exit Case Else MsgBox($MB_OK,"Service", "Cli usage:" & @CRLF & @CRLF & " -i : install service" & @CRLF & " -u : remove service" & @CRLF) Exit EndSwitch Else ;Here we init and start service if file called without cli arguments _Service_init($sServiceName) If @error Then MsgBox($MB_OK,"Service", "Cli usage:" & @CRLF & @CRLF & " -i : install service" & @CRLF & " -u : remove service" & @CRLF) EndIf Exit EndIf ;Here is test payload, demo just count timer diff Func _Service_payload($iArg, $sArgs) #region --> insert your running code here _Sleep(3000) logprint("Service Running Time Diff Is " & TimerDiff($hTimer) & @CRLF) #endregion EndFunc ;==>main ; Sleep function between write time diffs Func _Sleep($delay) Local $result = DllCall($hKernel32_DLL, "none", "Sleep", "dword", $delay) EndFunc ;==>_Sleep