|
-
March 21st, 2010, 01:36 PM
#1
Manually made a service, having trouble installing it!
Hi Everyone,
First trip to the forums and I hope this is an educated enough post.
I've written a service in C++ that performs some functions I need for my office. Right now, I'm manually issuing SC commands like:
sc MyService binpath= c:\Whatever\whatever.exe
To install the service, then I head up to services.msc and then set the service to start. After that, it works fine. But now, I have a question that I can't seem to get my head around:
How can I have the service install itself by someone just "double-clicking" it without using any other utility than basic code (no .NET, no ATL, no nothing but pure C++)?
Anyone that helps out will receive great praise and thanks from me.
-
March 21st, 2010, 02:05 PM
#2
Re: Manually made a service, having trouble installing it!
I would create a service using ATL and take a look at how it registers itself.
From there I use the same code in your project.
Btw, iirc, the ATL code requires a /service switch to be run in order to register the service. You'll need to modify this so this switch gets run when a user double-clicks on the service.
Lastly, on Vista and above, users will need to run your program as an admin in order to register it; otherwise the necessary registry entries won't get created.
-
March 21st, 2010, 02:26 PM
#3
Re: Manually made a service, having trouble installing it!
That's a really good idea. I'll try that.
Thanks!
-
March 23rd, 2010, 05:48 AM
#4
Re: Manually made a service, having trouble installing it!
just 4 completness:
The API to use is CreateService
If you want your exe to register itself, it should check, if it was started from the service control manager (this is: it's parent process is services.exe (or svchost.exe or srvany.exe)).
If it was not - it might use CreateService to register itself as a service. You should support a commandline switch /u for unregistration, as well.
regards
HoM
PS:
another way to register services is the SC command with the switch /create
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|