Jump to content

_Service_UDF v4 : Build your own service with autoit code


arcker
 Share

Recommended Posts

Right.

I've not added registry functions.

So the service is not well registered when you create it.

I've discovered it when i was trying to use the sc command : service doesn't exist.

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

at the creation, you have to enable in the type parameters , this flag : $SERVICE_INTERACTIVE_PROCESS

or if already created, edit the properties of your service and make it interactive.

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

if you try to make it interactive while you're not logged on, it's not possible.

for me the interaction is possible so i wonder what do you want to do exactly :)

-- 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 have been trying to get an AutoIt script to run as a service.

I need to be able to monitor a Logon Window, and when the user has logged on, detect subsequent windows, and interact with them from the script, by clicking on buttons, sending keystrokes, launching new programs, etc.

But I can not get this work at all.

When I run a script as service, it can not see all of the desktop windows.

If I uncheck the "Allow Service to Interact with Desktop" the script can see more windows than if it is checked.

I have tried: the service.au3 code, srvany, and even Cygwin's cygrunsrv service wrapper.

Clearly, I am missing something.

Should I be able to interact with any open window from inside a script that is running as a service?

Can anyone explain why I can not use Winlist from a script running as a service?

Can someone provide an example as to how to run an autoit script as a service, detect when someone has logged on, and then launch a program, and then interact with it from inside the script.

Thanks for any help.

Link to comment
Share on other sites

you have to understand two things :

- services are protected before logon to not let malicious software interact before the user login ( imagine a window that could replace the logon window ).

- SYSTEM is an account without user personification. So it can not acces to tihs layer.

- Services are made for agent or something, like antivirus. Their purpose are not to interact with windows or something.

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

This is just the code I need to run a program on the computers in my school, so the kids can't it stop from running! However, I can't get it to work. When I try to compile I get this error message

C:\FREECOM\AutoIt3\GTs Programs\service.au3(178,7) : ERROR: main(): undefined function.
    main()
    ~~~~~^

I'm confused. My program doesn't have a Function called "main" - the main code is enclosed in a While/Wend loop. What do I do?

Thanks,

Graham

Edited by GrahamT
Link to comment
Share on other sites

This is just the code I need to run a program on the computers in my school, so the kids can't it stop from running! However, I can't get it to work. When I try to compile I get this error message

C:\FREECOM\AutoIt3\GTs Programs\service.au3(178,7) : ERROR: main(): undefined function.
    main()
    ~~~~~^

I'm confused. My program doesn't have a Function called "main" - the main code is enclosed in a While/Wend loop. What do I do?

Thanks,

Graham

Wrap the While/Wend loop inside a Function called main().

edit:

Func main()
    While 1
        ;Service Code Loop
        sleep(10)
    WEnd
EndFunc   ;==>main
Edited by spudw2k
Link to comment
Share on other sites

Wrap the While/Wend loop inside a Function called main().

edit:

Func main()
    While 1
        ;Service Code Loop
        sleep(10)
    WEnd
EndFunc   ;==>main
Great! That worked fine - and its now compiling properly.

But, when I run it in Command Prompt window with -i on the end of the file name, I get Error 1063

The program runs - but its not showing in the services list.

Thanks,

Graham

Link to comment
Share on other sites

Great! That worked fine - and its now compiling properly.

But, when I run it in Command Prompt window with -i on the end of the file name, I get Error 1063

The program runs - but its not showing in the services list.

Thanks,

Graham

Anybody got any ideas on how to get this to work?

Thanks

Link to comment
Share on other sites

Anybody got any ideas on how to get this to work?

Thanks

It may attempting to run after you install it (depending on your code). It will fail if it is run this way. Do you see the service in the service control manager? Start -> Run -> services.msc It needs to be started by the SCM.
Link to comment
Share on other sites

It may attempting to run after you install it (depending on your code). It will fail if it is run this way. Do you see the service in the service control manager? Start -> Run -> services.msc It needs to be started by the SCM.

Thanks for that - yes I think it was attempting to run. Anyway, I already found a freeware program which will install it as a service:

RunAsSvc

Graham

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

So i've been playing with this for a while and have gotten it to work sometimes, but not all the time.

I'm running it on a windows 2003 server with the service properties adjusted to "allow service to interact with desktop".

If i use the example code it works exactly as it should, it displays a msgbox every 1 second.

But as soon as i modify the main function to the following it will not work. It runs the function, everything looks like it should be working, but it flat out does not work. The run function worked, but winwait and send also did not work.

func main()
    while 1
        WinClose("test.txt", "")
    Sleep(1000)
    WEnd
EndFunc
Edited by kjcdude
Link to comment
Share on other sites

remember that the purpose of a service is a background process. It can't interact with desktop like others process because it runs under SYSTEM account with somes limitations.

The purpose for me was to make a Nagios agent that could be stop / restarted and controlled by the services easily.

Whenever i see a script containing window manipulation function, i can say that the script will not runs well.

Sry it's a limitation, but a good limitation, for security reasons.

-- 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 purpose of a service is a background process. It can't interact with desktop like others process because it runs under SYSTEM account with somes limitations.

The purpose for me was to make a Nagios agent that could be stop / restarted and controlled by the services easily.

Whenever i see a script containing window manipulation function, i can say that the script will not runs well.

Sry it's a limitation, but a good limitation, for security reasons.

so why does srvany.exe, runasssvc.exe et al allow the scripts to run with gui and everything using Bitor($service_win32_ownproccess,$service_interactive_process) [spelling probably not right, I'm going off memory here at work... my code is at home=)], but the 'native' autoit routines do not?

also I've tried to read through and figure out my own troubles (posted in other thread), and found of MSDN that there's indeed a 'main()', and that's for console apps.

.. but there's also a 'winmain()' that should be used for GUI processes?

.. also if services were flat out not allowed to interact with users, what would even be the point of having a choice to interact with desktop at all?

.. also in reading about services (I really am trying to contribute, but I'm in way over my head methinks).. there is indeed the SCM which handles the service proccess if it is a console app...

... but for GUI (ie- interactive) the service should use SCP? it this right?

here's the thread and code I'm talking about:

http://www.autoitscript.com/forum/index.php?showtopic=83099

<--- confused now. Please forgive =)

Link to comment
Share on other sites

you're right, the is two types of processes.

The SCM can handle a console process so it's useful to debug a process while it's runing as process. I've not integrated for now.

I agree that it's not really easy. It took me 2 weeks ti understand the whole process and make this UDF? It was not really easy since nothing have been made before.

I don't like srvany since it just acts as a "intermediate" so i can't say what's he's doing. For me it just stats a process, and stop its two ( brutally ).

Will take a look, thx for your investigation it's always good to be curious, and really helpful for proof oc concept :P

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

  • 2 weeks later...

This is Nice..!!

Thanx for your hard work arcker, i've been waiting for this type of AutoIt feature for a while now..

Just a few questions though..

Is it possible to have the compiled script .exe, once ran from a double click, install itself as a Service without having to use CMD with the -I parameter..?? Then once Successfully installed start itself up.

And also how could we code in the configuration for the service's settings like: General, Log On, Recovery, Dependencies and all the sub-options for them Ect..??

Link to comment
Share on other sites

Is it possible to have the compiled script .exe, once ran from a double click, install itself as a Service without having to use CMD with the -I parameter..?? Then once Successfully installed start itself up.

http://www.autoitscript.com/forum/index.ph...st&p=579806

Also, check these out. If the service doesn't exist when it's run is asks if you want to install it.

http://www.autoitscript.com/forum/index.ph...st&p=578259

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...