arcker

_Service_UDF v4 : Build your own service with autoit code

365 posts in this topic




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 this post


Link to post
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 this post


Link to post
Share on other sites

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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

#10 ·  Posted

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

Share this post


Link to post
Share on other sites

#12 ·  Posted

I get error 1063 with a compiled script.

That is expected, just drop it on command prompt and add -i or whatever

 

.

eMyvnE

Share this post


Link to post
Share on other sites

#13 ·  Posted

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]

Share this post


Link to post
Share on other sites

#14 ·  Posted

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.

Share this post


Link to post
Share on other sites

#15 ·  Posted

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

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#18 ·  Posted

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]

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#20 ·  Posted

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


 

.

eMyvnE

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

  • Similar Content

    • rootx
      Compile question help
      By rootx
      I would like to ask you some questions about compiling.
      I use Autoit wrapper gui 15.920.938.0
      1. I would like to delete all comments from my compiled code.
      If is possible...
      I am using the 3.3.14.2 version of Autoit, I would like this time to protect my code, without using external tools that are seen as viruses, how do you protect your code usually?
      Thx
    • RaiNote
      Little Question
      By RaiNote
      Hello,
      Just a Little question why the autoit exes also with a very Little Code get when generated around 800-1000kb also would there be anyday away to compile a script to a Dynamic Link Library(dll)? Is there a way to Change to encryption of Compiling to something what makes the compile file a bit Shorter :O?
      Thanks in advance.
    • ur
      Version Missing
      By ur
      When we compile our code through Aut2exe, version is missing if we check the properties of the compiled executable.
      Can any one suggest how to set a version number to the compiled exe.
    • HelpfulToasty
      Compiling problems
      By HelpfulToasty
      So, I made a script, and I need to compile it so I can use it elsewhere and stuff. Whenever I try to compile it, I get an 
      Error: Unable to add resources.
      C:\Users\User\AppData\Local\AutoIt v3\Aut2Exe\???????.exe    ( - The "??????"'s change each time I try, but it's a .exe.)
      It's not my Anti Virus, I hope. My Anti Virus is Microsoft Security Essentials.
      Please help me.

    • pgupta
      Error reported while compling from editor "Aut2Exe has stopped working"
      By pgupta
      Hi ,
      I downloaded the latest autoIT.  I have an existing script that was working fine previously on another setup.
      But now eveytime i compile the same script, Aut2Exe got crashed.
       
      Error -
      Problem signature:
        Problem Event Name:    APPCRASH
        Application Name:    aut2exe.exe
        Application Version:    3.3.12.0
        Application Timestamp:    538b66aa
        Fault Module Name:    aut2exe.exe
        Fault Module Version:    3.3.12.0
        Fault Module Timestamp:    538b66aa
        Exception Code:    c00000fd
        Exception Offset:    000198b7
        OS Version:    6.1.7601.2.1.0.256.48
        Locale ID:    1033
        Additional Information 1:    076b
        Additional Information 2:    076bed14e3ca0113f4b80beb7b49b677
        Additional Information 3:    2eef
        Additional Information 4:    2eefb26b95dd8df84f531fd7cbccf9c9
      Read our privacy statement online:
        http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
      If the online privacy statement is not available, please read our privacy statement offline:
        C:\Windows\system32\en-US\erofflps.txt
       
      Help appriciated