arcker

_Service_UDF v4 : Build your own service with autoit code

375 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

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

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

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

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

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

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

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

    • WoodGrain
      By WoodGrain
      Hi All,
      I'm using UseTraySetIcon("shell32.dll", xx) to set my tray icon to a specific icon while running, is there a way I can specify this icon when I compile my script into an exe so my exe icon is the same?
      Thanks!
    • 9252Survive
      By 9252Survive
      Hello Guys, 
      Is there a way to have Auto it Exe messages/line number when you hover over the tray icon just at it shows when you run Au3.?
      For an example, if I the script has paused due to WinWait or Sleep I could hover over the icon and it shows the line where it's at. Is there a way to achieve the same with the compiled exe? 
      Many thanks for the help! 
       
    • Daka
      By Daka
      Hello there,
       
      When I compile script and use it out of the map where 
      the source code is. So just moving main.exe to
      other map, then source code is.
      It breaks with error:
      Line10010
      Error: Subscript used on non-accessible variable

      So I wonder what kind of file do I need to 
      include with .exe file? Or should I do something else?

      Because people that are using needs only .exe file
      just start it and use it, with out source code.

       
    • 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