# _Service_UDF v4 : Build your own service with autoit code

## Recommended Posts

• Replies 405
• Created

#### Popular Posts

I can't be responsible for any impact of your script or services you would run in production. | _Services_UDF v4 | | By Arcker | Run your script as a service | Req. AutoIt 3.3.8.1 min, last beta

Very nice arcker! Bout time this was done.

In v4 there is a bug in services.au3: Case $SERVICE_CONTROL_STOP,$SERVICE_ACCEPT_SHUTDOWN ; new in v4, stop when system shutdown ( better mmm ? ) https://msdn.microsoft.com/en-us/library/w

#### Posted Images

okkkkk

one feature requested for so long time, and no comment at all....

maybe the title is not enough explicit....

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
##### Share on other sites

Very nice arcker! Bout time this was done.

Spoiler

Misc Code Snippets:
Projects: SubnetCalc
Cool Stuff:

##### Share on other sites

okkkkk

one feature requested for so long time, and no comment at all....

maybe the title is not enough explicit....

Ahem.. "Silence is golden" >_<

Very nice arcker.

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
##### Share on other sites

Wow, exactly what I have been looking for, GOOD JOB !

##### Share on other sites

@ Thx all

I'm improving it to make it compatible with pause order and interrogate.

Bout time this was done.

What do you mean ? If you're talking about P-Trex method, using srvany, it's not a "standart" option.

Mine is the same method as all of the C++ program and other language program.

It was not possible before because callback was not implemented.

Any suggestions / improvements are welcome.

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
##### Share on other sites

very good UDF and example!

Website: www.cerescode.comForum: www.forum.cerescode.comIRC: irc.freenode.net , Channel: #Ceres--------------------Autoit Wrappers, Great additions to your script (Must See) (By: Valuater)Read It Befor Asking Question Click Here...--------------------Join Monoceres's Forums http://www.monoceres.se--------------------There are three kinds of people: Those who make things happen, those who watch things happen, and those who ask, What happened? Casey Stengel
##### Share on other sites

Hey man great work! I was wondering what I should do though, I keep getting Error 0. When I try and run your example script or one of my own such as this:

#include<Service.au3>
_Service_Init("TestSerice")
While 1
ConsoleWrite("Loop"&@CRLF)
Sleep(100)
WEnd
##### Share on other sites

because you run it in debugger...

so it is your autoit3.exe that runs.

Tomkae your script work, compile it and create a service linked to it.

my example integrates an install / uninstall option.

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
##### Share on other sites

I tried compiling the example script you provided above as well and sucsesfully installed the process. Should I now just re-exucaute the script without any params? Or is there something esle I should do before that. I also noticed the main() function was not run so I put it in after _Service_Init, and that is when I get error 0. Any ideas?

I apologize for my inconvienience, I am new to the whole service idea.

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_Change2CUI=y
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
; Example of using service UDF to make an exe possibly runeed as a service
; By Arcker
; 10/09/2008
#include<Service.au3>
$sServiceName = "Autoit_Service" If$cmdline[0] > 0 Then
Switch $cmdline[1] Case "install", "-i", "/i" InstallService() Case "remove", "-u", "/u", "uninstall" RemoveService() Case Else ConsoleWrite(" - - - Help - - - " & @crlf) ConsoleWrite(" Service Example params : " & @crlf) ConsoleWrite(" -i : install service" & @crlf) ConsoleWrite(" -u : remove service" & @crlf) ConsoleWrite(" - - - - - - - - " & @crlf) Exit ;start service. EndSwitch EndIf _Service_init($sServiceName)
main()
Func main()
While 1
ConsoleWrite("IN MAIN"&@CRLF)
;doing what you want here
Sleep(1000)
WEnd
EndFunc  ;==>main
Func InstallService()
ConsoleWrite("Installing service, please wait" & @CRLF)
_Service_Create("", $sServiceName, "Autoit Service Test", @ScriptFullPath) If @error Then ConsoleWrite("Problem installing service, Error number is " & @error & @CRLF & " message : " & _WinAPI_GetLastErrorMessage()) Else ConsoleWrite("Installation of service successful") EndIf Exit EndFunc ;==>InstallService Func RemoveService() _StopService("",$sServiceName)
_DeleteService("", $sServiceName) if not @error then ConsoleWrite("service removed successfully" & @crlf) Exit EndFunc ;==>RemoveService ##### Link to post ##### Share on other sites I get error 1063 with a compiled script. Spoiler Things I've Made: Transparency Machine Misc Code Snippets: Projects: SubnetCalc Cool Stuff: ##### Link to post ##### Share on other sites I get error 1063 with a compiled script. That is expected, just drop it on command prompt and add -i or whatever . eMyvnE ##### Link to post ##### Share on other sites ok i'll try to reexplain. the example script contains a sort of autoinstall / uninstall. Please dinstinguish it from the whole service processus. 1 - Compile the example 2 - Choose an appropriate location and copy the script here. 3 - open a command prompt, and execute the compiled script with option -i 4 - start / execute "services.msc" . You will see a service called "Autoit_service". you can execute "sc query" in a command prompt too. 5 - Launch it : it will run the previous compile script. The main function will be executed after the service_init. 6 - stop and relaunch the service as you wish. Error 1063 : follow this procedure. Don't run it from scite Error 0 : same -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects : [list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] ##### Link to post ##### Share on other sites I still experience error 1063. even though it is compiled and installed. If I run it directly it errors. If I start it from the SCM it starts but I do not get the expected results. Spoiler Things I've Made: Transparency Machine Misc Code Snippets: Projects: SubnetCalc Cool Stuff: ##### Link to post ##### Share on other sites for me it works !! you have to open a command prompt and type "Service_Example.exe /i" type: SC QUERY you get the result: SERVICE_NAME: Autoit_Service DISPLAY_NAME: Autoit Service Test TYPE : 10 STATE : 4 R ( WIN32_EXIT_CODE : 0 ( SERVICE_EXIT_CODE : 0 ( CHECKPOINT : 0x0 WAIT_HINT : 0x0 ##### Link to post ##### Share on other sites for me it works !! >_< be sure you have administrator privileges !!!!!!!!!!!!!!!!! you have to open a command prompt and type "Service_Example.exe /i" type: SC QUERY you get the result: SERVICE_NAME: Autoit_Service DISPLAY_NAME: Autoit Service Test TYPE : 10 STATE : 4 R ( WIN32_EXIT_CODE : 0 ( SERVICE_EXIT_CODE : 0 ( CHECKPOINT : 0x0 WAIT_HINT : 0x0 @Arcker greate stuff, well done Edited by Micha1405 ##### Link to post ##### Share on other sites So from what I can tell, the service starts fine, but my main function never runs. my main func consists of a filewrite to c:\text.txt and a 10 second sleep. Inside a while loop of course Edited by spudw2k Spoiler Things I've Made: Transparency Machine Misc Code Snippets: Projects: SubnetCalc Cool Stuff: ##### Link to post ##### Share on other sites remember that the service runs under system account privileges. i didn't test some function in the while loop because it's seems logical that it loop here. plz post the code here. i'll take a look. I don't pretend that there is no bug -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects : [list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] ##### Link to post ##### Share on other sites remember that the service runs under system account privileges. i didn't test some function in the while loop because it's seems logical that it loop here. plz post the code here. i'll take a look. I don't pretend that there is no bug I appreciate any support you can give. Great job so far. #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Version=Beta #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; Example of using service UDF to make an exe possibly runeed as a service ; By Arcker ; 10/09/2008 #include<Service.au3>$sServiceName = "Autoit_Service"
If $cmdline[0] > 0 Then Switch$cmdline[1]
Case "install", "-i", "/i"
InstallService()
Case "remove", "-u", "/u", "uninstall"
RemoveService()
Case Else
ConsoleWrite(" - - - Help - - - " & @crlf)
ConsoleWrite(" Service Example params : " & @crlf)
ConsoleWrite("  -i : install service" & @crlf)
ConsoleWrite("  -u : remove service" & @crlf)
ConsoleWrite(" - - - - - - - - " & @crlf)
Exit
;start service.
EndSwitch
EndIf
_Service_init($sServiceName) Func main() While 1 ;doing what you want here fileWrite("C:\test.txt",@ComputerName & @TAB & @ScriptName & @CRLF) Sleep(10000) WEnd EndFunc ;==>main Func InstallService() ConsoleWrite("Installing service, please wait" & @CRLF) _Service_Create("",$sServiceName, "Autoit Service Test", @ScriptFullPath)
If @error Then
ConsoleWrite("Problem installing service, Error number is " & @error & @CRLF & " message  : " & _WinAPI_GetLastErrorMessage())
Else
ConsoleWrite("Installation of service successful")
EndIf
Exit
EndFunc   ;==>InstallService
Func RemoveService()
_StopService("", $sServiceName) _DeleteService("",$sServiceName)
if not @error then ConsoleWrite("service removed successfully" & @crlf)
Exit
EndFunc   ;==>RemoveService
Edited by spudw2k
Spoiler

Misc Code Snippets:
Projects: SubnetCalc
Cool Stuff:

##### Share on other sites

So, when is that function 'main()' called?

.

eMyvnE

## Create an account

Register a new account

• ### Similar Content

• HI people,
I got a questions, I maintain code in autoIT and every time I compile a new version or modification, Scite generate 2 folders. One folder is finish by released and the other is tentative. I try to make some google search, but never find answer would satisfied myself. The dev who was maintain it before were using AutoIt3Wrapper_GUI, and I don't know if it's related. I look both folder, but they seem pretty identical, but I would like to know what it's the difference between those to folder. Anyone have a clue?
• By Rhidlor
I don't have any experience compiling AutoIt scripts or know of any best practices regarding said scripts so I was wondering, what are some of the options for passing data to complied scripts? Here's an example of what I mean by "option": Writing data to a text file, then running a script which reads the data from that text file.
Thanks!
I apologize if this topic is a little lackluster
• By Skeletor
Hey All,
Yes, this is an odd request.
But is there a way to bulk up the size of the compiled program?
I know many want to reduce it's size, but I want to increase it.
What methods do you suggest?
• By dimm
Is it possible to compile script without any icon resources included?
When I make exe it uses default system icon of current OS even if I compile as console application.
On other versions of Windows it looks a little strange

Update:
It seems that the only way is remove icons from exe after compilation using resource editors like ResHacker.

Using corrupted 35 bytes icon file. Windows can't load it and shows default system icon.
#pragma compile(Icon, broken.ico) broken.ico

• Hi,
Since today, exe's are being flagged as having a trojan by Windows Defender (Fuery.B!cl)
Version:  3.3.14.3 - SciTE Version 3.7.3

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...