somebody Posted December 26, 2007 Share Posted December 26, 2007 I have used code posted here and here as guides to installing and running my AutoIt script as a service, but it is still not properly starting. After starting the service through Windows' "Services" manager, my script attempts to start but then dies after 30 seconds with an error of:Error 1053: The service did not respond to the start or control request in a timely fashion.Do I need some sort of return value passed from the AutoIt script to Windows so Windows will know the service started correctly?Here is my code. It will print "hello world" 30 times to the log file until it dies. Any help is greatly appreciated, thanks!CODE#NoTrayIcon#include <process.au3>Dim $servicename = "HelloWorld"Dim $log = "c:\temp\log.txt"Dim $is_service_installed = 0Dim $strComputer = "."Dim $OWN_PROCESS = 16Dim $NORMAL_ERROR_CONTROL = 1Dim $INTERACTIVE = trueCheck_Service_Installation()If( $is_service_installed == 0 ) Then Install_Service()Else WriteLog( $log, "Service already installed, skipping service installation" ) While 1 sleep(1000) WriteLog( $log, "Hello World" ) WEndEndIfFunc Install_Service() Dim $objWMIService, $objService, $objServices, $colListOfServices, $strService $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $objService = $objWMIService.Get("Win32_BaseService") $errReturn = $objService.Create( $servicename, "Hello World!", @AutoItExe, $OWN_PROCESS, $NORMAL_ERROR_CONTROL, "Automatic", $INTERACTIVE, "LocalSystem", "" ) WriteLog( $log, "Service installed" )EndFuncFunc Check_Service_Installation() Dim $objWMIService, $objService, $colListOfServices, $strService $objWMIService = ObjGet("winmgmts:root\cimv2") $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service") For $objService in $colListOfServices If( $objService.Name == $servicename ) Then $is_service_installed = 1 EndIf NextEndFuncFunc WriteLog($filename, $line) $fh = FileOpen($filename, 1) $ts = @YEAR & "." & @MON & "." & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & " -- " FileWriteLine($fh, $ts & $line) FileClose($fh)EndFunc Link to comment Share on other sites More sharing options...
weaponx Posted December 26, 2007 Share Posted December 26, 2007 Did you try the example in the FAQ? (Question 4)http://www.autoitscript.com/forum/index.php?showtopic=37289 Link to comment Share on other sites More sharing options...
somebody Posted December 30, 2007 Author Share Posted December 30, 2007 (edited) Yes, I followed the examples in the FAQ. I used "ServiceControl.au3" from SumTingWong's post: http://www.autoitscript.com/forum/index.php?showtopic=6487.I did not use WinVNC as his "test.au3" uses. Instead, I used the following simple test script that prints "Hello World" to a file (this is not the same as my first script above):CODE#NoTrayIcon#include <process.au3>Dim $log = "c:\temp\log.txt"While 1sleep(1000)WriteLog( $log, "Hello World" )WEndFunc WriteLog($filename, $line)$fh = FileOpen($filename, 1)$ts = @YEAR & "." & @MON & "." & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & " -- "FileWriteLine($fh, $ts & $line)FileClose($fh)EndFuncHere is my modified "test.au3" from SumTingWong:CODE#include "ServiceControl.au3"Dim $nRet; Create/delete the helloworld serviceIf _ServiceExists("", "helloworld") ThenMsgBox(4096,'debug:' , 'helloworld service exists') ;### Debug MSGBOX If _ServiceRunning("", "helloworld") Then MsgBox(4096,'debug:' , 'helloworld service running') ;### Debug MSGBOX If _StopService("", "helloworld") Then Sleep(1000) MsgBox(4096,'debug:' , 'helloworld service stopped') ;### Debug MSGBOX If _DeleteService("", "helloworld") Then MsgBox(4096,'debug:' , 'helloworld service deleted') ;### Debug MSGBOX EndIf EndIf Else If _DeleteService("", "helloworld") Then MsgBox(4096,'debug:' , 'helloworld service deleted') ;### Debug MSGBOX EndIf EndIfElse $nRet = _CreateService("", _ "helloworld", _ "Hello World", _ "c:\dev\hello_world.exe", _ "LocalSystem", _ "", _ BitOR($SERVICE_WIN32_OWN_PROCESS, $SERVICE_INTERACTIVE_PROCESS)) If $nRet Then MsgBox(4096,'debug:' , 'helloworld service created') ;### Debug MSGBOX If _StartService("", "helloworld") Then MsgBox(4096,'debug:' , 'helloworld service started') ;### Debug MSGBOX EndIf Else MsgBox(4096,'debug:' , 'Failed to create helloworld service: ' & @error) ;### Debug MSGBOX EndIfEndIfSumTingWong's "test.au3" generates a popup message saying "helloworld service created". My "Hello World" script then runs for 30 seconds, but then stops. An error is then entered into the Windows Event Log:The Hello World service failed to start due to the following error: The service did not respond to the start or control request in a timely fashion.So I ask again: Does my "Hello World" script need to return anything to notify Windows that it correctly started? Thanks for your help. Edited December 30, 2007 by somebody Link to comment Share on other sites More sharing options...
somebody Posted December 31, 2007 Author Share Posted December 31, 2007 I got my "Hello World" script working with "runassvc". For some reason, it would not work through any other method. Oh well, but thanks for your help Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now