Sign in to follow this  
Followers 0
UglyBob

compiling EXE to run as a service

10 posts in this topic

I'm trying to create an app which will run as a service and appear in the system tray. I've created the service using SRVANY and it works fine until the user logs off, the app closes down. Initial tests at home made me think I had resolved the issue but in work it still fails, this drove me crazy until I replicated the exact environment, i.e. the version of AutoIT. When using the latest version the script will close everytime a user logs off the PC. I then ran a test with one of the help examples (traycreatemenu) compiled in the latest version and an older version (3.2.4.9) which I was using at home. Lo and behold the script remains when the user logs off then back on etc. using the old version of autoit (aut2exe) but running the same script compiled in the latest version the script closes everytime.

Unfortunately I can't compile my script using the old version of autoit due to the commands and 'includes' used, so I'm stuck.

I've read numerous postings about using SRVANY and even contemplated using the service.au3 options but this although more impressive as a service doesn't work well with GUI's (at least with what I've tried).

There may be something written somewhere in the myriad of text, small print and help which may explain this but does anyone have any ideas as to why an older version of this great tool should allow me run a GUI interactively as a service but the latest not? Is this something to do with complying more rigidly with Microsoft or other coding standards?


"My God, you're looking hideously ugly today, Ugly Bob."

Share this post


Link to post
Share on other sites



I have been working on this too. What OS are you using?

Share this post


Link to post
Share on other sites

Windows XP and Windows Server 2003


"My God, you're looking hideously ugly today, Ugly Bob."

Share this post


Link to post
Share on other sites

as a work around could you not use group policy or in the all users folder call a second executable / bat file that starts the service upon user logon?

Share this post


Link to post
Share on other sites

The only problem with that is the script will then only restart when a user logs back on the PC, if the user logs off and then leaves the PC alone the service (or rather my app which is called by the SRVANY service) will not run.


"My God, you're looking hideously ugly today, Ugly Bob."

Share this post


Link to post
Share on other sites

what does your script do? that may help us to identify a fix.. :-)

Share this post


Link to post
Share on other sites

Take a look here: http://www.autoitscript.com/wiki/FAQ#How_can_I_run_my_script_as_a_service.3F

Share this post


Link to post
Share on other sites

Thanks, but I'm already aware of this and other possible alternatives to executing scripts in windows.

My actual script is a powerdown script. You know, the usual monitor a PC and shutdown if not in use. To be honest this is irrelevant as the actual issue here is the use of compiled scripts as services using the latest version of AutoIT. No matter what I compile the old version works but the new doesn't. I know there are a multitude of similar scripts/software out there but I would like to achieve this little pet project myself if I can. If no-one can shed any light in this issue I might review the script and see if I can re-write it using the commands available in the older version of autoIT.


"My God, you're looking hideously ugly today, Ugly Bob."

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

It looks like this whole issue has something to do with 'opt ( "onExitFunc' .....).

With a bit of jiggery-pokery I've got my script working with the older version, and everything works perfectly. I then decided to try and include additional tasks on 'exit'. As soon as I added a function for OnExitFunc and query @EXITMETHOD the script once again closes down when the user logs off. Even with the actual function called contains absolutely nothing it still closes. So, is the latest compiler 'Aut2Exe' adding this or something similar to my script?

This is only info, if it's help for anyone in a similar situation. It would be nice if I could use the current version of AutoIT but am happy to continue using the older version for this particular script of mine.

Edited by UglyBob

"My God, you're looking hideously ugly today, Ugly Bob."

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • ChipConnJohn
      By ChipConnJohn
      Hello all,
      I've scripted AutoIT to scrape a web forum I'm part of using the IE.au3 #include.  The script works great if I'm logged in, but doesn't work as a service.  Anyone have any ideas on how I might achieve that or will I have to have the computer logged in at all times?
      Thanks,
      -John
    • Kirky
      By Kirky
      Hello Again Legends of AutoIT
      I am immensely grateful for the help I was given in creating my first script which works (almost) perfectly when logged on to a PC with admin rights.
      The problem is that I need to silently install the application on to 50 PCs that do not have admin rights. We have a homemade distribution tool but basically a log on script runs, checks if your in an AD group and if you are it installs the application. The problem I have is that the user that installs the application is actually a service run as a user and this means that there is no UI.
      My script doesn't seem to run correctly or at least the application is not installed and I don't know enough about AutoIT basics (yet) to know whether it can be used in this context.
      I'm more than happy to give more information or share my script if this is not enough information to go on.
      Thanks in advance
    • musicstashall
      By musicstashall
      Excuse me, I did not understand how in the function of Main I can include hundreds of functions of my executable code ?? How to implement this?
    • wtarkan
      By wtarkan
      If I create a service to run a program , Application window cannot Appear - How can I make the App window visible
    • tremolux66
      By tremolux66
      I'm unable to display a message box from a compiled AutoIt alerting script that is executed from a service (also a compiled AutoIt script). I used $MB_SERVICE_NOTIFICATION, but the dialog doesn't appear and the alerting script continues as if the OK button had been clicked. The service script uses ShellExecute() to launch the alerter (as opposed to a *Wait() call) so it can continue processing. Note that we used Windows Service Wrapper (winsw) to turn the compiled script into a service but haven't identified any issues from it.
      I tried the one-line execute example given in this thread: Message box timeout not working
      ; 2097152 = $MB_SERVICE_NOTIFICATION $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(2097152, ''' & $sTitle & ''', ''' & $sText & ''')"') without the timeout code, but no luck: the MsgBox does not appear. (In any case, we don't have AutoIt installed on the target system, so it would have to be converted into a .exe file.)
      We're developing and unit-testing on Win 7 Enterprise; the target OS is Win 7 Pro, and the AutoIt version is 3.3.14.2.
      Any solutions or suggestions will be much appreciated. Code fragments are below.
      Thanks.
       
      The following code fragment is the relevant portion of the alerting script that displays the MsgBox:
      [...] ; Alert the operator that there's a problem with the recording $sFeed = $aRecInfo[6] $sSession = $aRecInfo[2] $sTemp = $aRecInfo[4] $sDate = _FormatDate($sTemp) $sTemp = $aRecInfo[5] $sTime = _FormatTime($sTemp) _Debug2("Inactive recording feed " & $sFeed & ", Session=" & $sSession & ", Start Date/Time=" & _ $sDate & " " & $sTime) $sErrorMsg = "ERROR: Feed " & $sFeed & " for session " & $sSession & " stopped, notify reporter immediately" $iMbFlag = $MB_SERVICE_NOTIFICATION _Debug1("Displaying MsgBox...") MsgBox($iMbFlag, "INTERVIEW RECORDING ERROR", $sErrorMsg) _Debug1("Returned from MsgBox") [...]  
      And the calling code fragment in the service is:
      ; Walk through the array backwards so we don't end up evaluating an index that doesn't exist For $iIndex = UBound($aFeedArray)-1 To 0 Step -1 [...] ; Before timing-out the feed, check for a .mpgpart file (=> feed may still be recording) $sDirPath = $sDirTemp & "\" & $sFeedTemp & "\" & $aFeedArray[$iIndex][$cSessionName] $sMpgPartName = GetMpgPart($sDirPath, $sFeedTemp) If StringLen($sMpgPartName) > 0 Then ; If .mpgpart file name hasn't changed in more than $iDeadFeedTime seconds, then declare feed dead ; ========v Test code to force error v======== $sMpgPartName = $aFeedArray[$iIndex][$cMpgPartName] ; ========^ Test code to force error ^======== _Debug2("Just set $sMpgPartName to '" & $sMpgPartName & "', should fall into dead-feed code") If $sMpgPartName = $aFeedArray[$iIndex][$cMpgPartName] Then ; Name is same => feed is dead: alert the operator and delete the feed w/out stop-processing _Debug2("Feed " & $sFeedTemp & " looks dead -- alerting the operator") _Debug2("Delete GUID " & $aFeedArray[$iIndex][$cGUID]) ; ======== Alert app execution ======== ; $sAlertApp = @ScriptDir & "\" & "RecAlert.exe" $iChildPid = ShellExecute($sAlertApp, $sDirPath, "", "open") _Debug2("Alert app: ShellExecute(): " & _RetStr($iChildPid, @error, @extended)) _ArrayDelete($aFeedArray, $iIndex) Else ; Otherwise, the .mpgpart name has changed, reset the timer, store the name, and continue _Debug2("Feed " & $sFeedTemp & " timeout, but has new .mpgpart file -- continuing") $aFeedArray[$iIndex][$cDateTime] = TimerInit() $aFeedArray[$iIndex][$cMpgPartName] = $sMpgPartName EndIf ContinueLoop EndIf [...] Next