jawnah Posted February 19, 2009 Share Posted February 19, 2009 I've been working on an AutoIT script that will allow me to run a GUI application (that provides a splash screen for a batch-loaded application) as a service in Windows. I'm experiencing an issue with the script where, once compiled as an EXE and installed as a service (using "sc"), the system doesn't recognize that the service is starting. It actually launches the application and I see my GUI screens (because the "Interact with Desktop" feature is turned on), but the system continues showing the "Starting" status for the service and eventually complains that the service has taken too long to respond. This obviously makes for an ugly start-up and is undesirable. I was able to get the same process to work as a service using the _Service.au3 script that I found posted on this forum. However, once I did that, the GUI components no longer showed and every time I started the service, I got various system beeps (from what I think were invisible dialog boxes trying to show me errors). Based on my testing and the results above, I assume that I'm missing some sort of command channel for communicating the status of the service to the Windows Services system. However, in my research, I can't seem to figure out how I'd go about establishing such a channel, if that's even my problem. Does anyone have any suggestions? Also, I'm new to this scripting language, so if I've got something below that is bad form, please feel free to point it out (such as how I formed my array that I wish would start as 0!). I've posted my code below: expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <UpdownConstants.au3> #include <Array.au3> #NoTrayIcon main() ; Function to start the app Func main() Local $splashGui, $splashMsg, $splashText, $posProcess, $posOut, $startupString, $splashStatus, $splashProgress, $posOut2, $posOut3 Local $pubDirectoryBound, $startupSize, $startupCount, $tempLine, $tempLine2, $startupSteps, $arrayStartupSteps, $startupIncrement Local $readBuffer, $bufferArray, $startupTotal, $arrayPos Dim $arrayStartupSteps[1] _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): local tech LogTechnician started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): local tech LocalDT started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): local tech UITechnician started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): local tech DeviceTechnician started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): local tech ResourceTechnician started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): local tech JournalTechnician started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): local tech ParameterTechnician started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): manager UtilityManager started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): manager PrintableDocumentManager started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): manager JournalFormatterManager started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): manager ResourceManager started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): manager SecurityManager started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): manager JournalManager started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): manager TIERMANAGER started.") _ArrayAdd($arrayStartupSteps, "Dispatcher.configureDispatcher(): local app APPLICATION started.") _ArrayDelete($arrayStartupSteps, 0) $splashGui = GUICreate("Splash Screen", 500, 300) $splashStatus = GUICtrlCreateLabel("POS Application Status", -1, 5, 500, 25, $SS_CENTER) $splashProgress = GUICtrlCreateProgress(5, 30, 495, 20) $splashText = GUICtrlCreateEdit("", -1, 50, 475, 250, $ES_MULTILINE + $ES_AUTOVSCROLL,$UDS_WRAP) GUISetState() GUICtrlSetData($splashText, "Starting application..." & @CRLF, 1) GUICtrlSetData($splashText, "There are " & String(UBound($arrayStartupSteps)) & " items in the startup array." & @CRLF, 1) $startupIncrement = 100 / UBound($arrayStartupSteps) $startupIncrement = Round($startupIncrement) GUICtrlSetData($splashText, "-- We will be using increments of " & String($startupIncrement) & " for status" & @CRLF, 1) GUICtrlSetData($splashText, "The length of CRLF is " & StringLen(@CRLF) & @CRLF, 1) $posProcess = Run("C:\someapp\start.bat", "C:\someapp",@SW_MINIMIZE,$STDOUT_CHILD + $STDERR_CHILD) Do $splashMsg = GUIGetMsg() $posOut = StdoutRead($posProcess) $readBuffer = $readBuffer & $posOut If Not StringInStr($posOut, @CRLF) Then ContinueLoop Else $bufferArray = StringSplit($readBuffer, @CRLF, 2) If Not StringRight($readBuffer, 2) = @CRLF Then $readBuffer = _ArrayPop($bufferArray) Else $readBuffer = "" EndIf EndIf For $i In $bufferArray If $i = "" Then ContinueLoop EndIf GUICtrlSetData($splashText, "-- Received: " & $i & @CRLF, 1) $arrayPos = _ArraySearch($arrayStartupSteps, $i) If $arrayPos > -1 Then GUICtrlSetData($splashText, "-- Found startup string!" & @CRLF, 1) $startupTotal = $startupTotal + $startupIncrement If $startupTotal > 100 Then $startupTotal = 100 EndIf GUICtrlSetData($splashProgress, $startupTotal) If $arrayPos = UBound($arrayStartupSteps) - 1 Then GUICtrlSetData($splashText, "-- Found last startup item, application done!" & @CRLF, 1) EndIf EndIf Next Until $splashMsg = $GUI_EVENT_CLOSE Exit EndFunc jawnah--Have a blessed day :) Link to comment Share on other sites More sharing options...
jawnah Posted February 19, 2009 Author Share Posted February 19, 2009 I was able to resolve this problem. If I'd read the included services control file a little better, I'd have realized I needed to name my main() function _Main(). Problem is somewhat resolved. Now that the GUI displays, I have a GUI updating problem, but I'll post about that in the other forum. jawnah--Have a blessed day :) 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