Jump to content

_Service_UDF v4 : Build your own service with autoit code


arcker
 Share

Recommended Posts

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]
Link to comment
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]
Link to comment
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
Link to comment
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
Link to comment
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]
Link to comment
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 comment
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 comment
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.

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

×
×
  • Create New...