Jump to content

Compiling EXE to run as a Service


Recommended Posts

   I am going to have to apologize. I have a similar thread so I know starting a second one is against forum rules but the amount of information I have collected and the direction I am taking is so radically different than the first thread I am going to try it again.

   The bottom line is "has anyone ever compiled a script, turned it in to a service and had it run prioperly?".

   After two weeks of searching and Googling I just today came across this AutoIT thread:

'?do=embed' frameborder='0' data-embedContent>>

It is my problem to a T. My program will boot and run as a servive until I log out at which point the service stops and will not work again until I restart it. Exact same senario as the link. This link is two years old and there never was a resolution. The thread just died.

   I tried using EXE2Service as a helper with no luck then came across this Wiki:

http://www.autoitscript.com/wiki/FAQ#How_can_I_create.2Fstart.2Fstop_or_otherwise_control_a_service.3F

and have had no luck with the example "CreateService" using srvany. The example returns a success yet the service is not created.

Then there is this link which is supposed to be an AutoIT wrapper which will turn native AutoIT code in to a runnable EXE:

but it too doesn't work and the whole thread just dies. There are several exmples and UDFs but too many versions of each and none that really work.

   It is almost as if running a compiled scripts is taboo. No one talks about it, no one really does it and even the Wiki is incorrect and doesn't work. Surely there has to be others out there trying to use compiled EXEs as Services no? Has anyone every done it successfully?

Link to comment
Share on other sites

Have you tried this UDF? '?do=embed' frameborder='0' data-embedContent>>

It seems to be the most popular about building own Services and it has been updated less than a year ago...

Edited by j0kky
Link to comment
Share on other sites

   I tried asking questions and getting help on that UDF but it is like a dead thread. No one is contributing to that one any more. I did find yet another thread here about running srvany and I think it pinpoints the problem:

"For WIN32 graphical applications: when the currently logged-in user is logging-off, all WIN32 top-level windows receive WM_QUERYENDSESSION and WM_ENDSESSION messages. Some WIN32 applications choose to terminate upon receipt of such messages. In order for your WIN32 application to survive logoff, it must not do that: instead, your windows procedure should call the default windows procedure on these messages"

   That pretty much sums up what is going on. I have a feeling there is virtually no one in this forum running scripts as services because this appears to be a very common problem with helpers like srvany. I am using exe2service and the problem exists with it too.

   So based on the above quote maybe I need to re-word my question to something like: Is there any way to code my program so it will ignore WM_QUERYENDSESSION and WM_ENDSESSION and keep running?

Link to comment
Share on other sites

If you don't write your script with an UDF like the one I linked, what is the scope of building an application as service? You just have to write an idle loop and build it like a normal application...

Edited by j0kky
Link to comment
Share on other sites

@j0kky I am sory but I have no idea what you were trying to convey with your last pot. Can you enlighten me?

If you seem insistant on using that UDF here is what I mean. Here is my code:

While 1
   CheckMainProgram()
   Sleep(2000)
   WEnd

Func CheckMainProgram()
If ProcessExists("Notepad.exe") <>  0 Then
   Return
   EndIf
Run("C:\Windows\Notepad.exe")
EndFunc

I inserted that in the ServiceExample_V3 where it said to and compied it. When I used the -i option it did nothing. No error message. No service creation. Nothing. If you seem insistant on using this UDF can you point me to the latest and greatest because there are a couple files posted throughout the 17 page thread and I am not sure which one I should be using. Also why don't I get anything with the -i option?

I would much rather find out how to write a program that ignores the WM_ENDSESSION but if you use this UDF and know it will solve the problems I am willing to give it a go. Thanks!

Edited by Trax
Link to comment
Share on other sites

I will try to explain it in other words.

First: I never needed to write or compile a service in Autoit and absolutely I have no interest to suggest you that particular UDF.

MSDN documentation says: "a service application conforms to the interface rules of the Service Control Manager (SCM)"; that's why in my opinion it doesn't make sense to spend time writing an application as a Windows service without having special needs.

The script that you wrote points exactly what I'm trying to tell you: for example if you add #notrayicon statement, you compile and save it to C: and then you add it at startup creating a new registry key in:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

Do you notice some difference from a service?

It is another question if you need some special service function.

Edited by j0kky
Link to comment
Share on other sites

I have never made a service. I read your old thread and there was a link to a wiki - http://www.autoitscript.com/wiki/FAQ#How_can_I_create.2Fstart.2Fstop_or_otherwise_control_a_service.3F. You seem to be very secretive about your code. If your code is not service compatible then what do you want to hear? What part of your code isn't service compatible? Also why the secrecy?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

@Trax: I didn't read your last thread, otherwise it would have been much simpler.

BTW I might insist: you don't need a service, some time ago I wrote this simple script, it is a normal application and the shutdown process doesn't close it until all other applications were closed :

#Include <WinAPIEx.au3>

_WinAPI_SetProcessShutdownParameters(0x0100)

While 1
    $Msg = GUIGetMsg()
WEnd

I think that's exactly what you are looking for in the other thread, otherwise I leave the thread to those who know more than me in the field of services :)

Edited by j0kky
Link to comment
Share on other sites

@Trax: I didn't read your last thread, otherwise it would have been much simpler.

BTW I might insist: you don't need a service, some time ago I wrote this simple script, it is a normal application and the shutdown process doesn't close it until all other applications were closed :

#Include <WinAPIEx.au3>

_WinAPI_SetProcessShutdownParameters(0x0100)

While 1
    $Msg = GUIGetMsg()
WEnd

I think that's exactly what you are looking for in the other thread, otherwise I leave the thread to those who know more than me in the field of services :)

I'm not sure this will work for windows is doing a forced shutdown on the AutoIt app. It would have to be tested to confirm if it would work or not.

Link to comment
Share on other sites

The example posted won't work.

j0kky,

In future it's better to link to the function's help file page rather than post code which is practically useless to the OP.

_WinAPI_SetProcessShutdownParameters() ; Hint: Click me.
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@MBALDEZSHARI: I have understood by >this post there is no forced shutdown on Autoit app (the script works just because there is no forced shutdown, there is no way to abort definitely a shutdown if the user doesn't press on "cancel shutdown")

@guinness: I've link that pseudo-code just to show that function comes first than the loop, in future I'll follow you advice. Anyhow it works on Win XP, Vista and 7.

Edited by j0kky
Link to comment
Share on other sites

@MBALDEZSHARI: I have understood by >this post there is no forced shutdown on Autoit app (the script works just because there is no forced shutdown, there is no way to abort definitely a shutdown if the user doesn't press on "cancel shutdown")

The user IS clicking on cancel before the shutdown gets too far along and killing the AutoIt script. That is the reason the OP wants to run something as a service to restart the AutoIt script if the user does this.

Link to comment
Share on other sites

We misunderstood cause my bad english! We are saying the same thing: there is not a forced shutdown because the user is clicking on cancel before the shutdown gets too far along and killing the AutoIt script, this is the reason because my script works. In fact the system try to end all application (including wordpad, where it is blocked) before ending my script. So it is still alive when the user press on cancel!

Link to comment
Share on other sites

What is wrong with >_AlwaysRun()?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@computergroove I have no idea what part of my code isn't service compatible. That was yet another question. Some threads say AutoIT code is service compatible other threads say it isn't. I believe the latter. I have yet to find a thread about making your AutoIT script service compatible. There is no secrecy. 1) the code is too long to post and 2) the code is moot. Not even remotely related to the question. The only thing posting code would do is give people the chance to go off topic and worry about the code and not the question.

@j0kky it looks like you are correct. _WinAPI_SetProcessShutdownParameters(0x0100) seems to do the trick. At least with XP. I can cancel a shutdown in progress and the program stays running. I still have a lot of testing to do on Win7/8. Will keep you posted. Thanks!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...