CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2010
    Posts
    3

    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.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.

  3. #3
    Join Date
    Mar 2010
    Posts
    3

    Re: Manually made a service, having trouble installing it!

    That's a really good idea. I'll try that.

    Thanks!

  4. #4
    Join Date
    Jan 2005
    Location
    germany
    Posts
    160

    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
  •  





Click Here to Expand Forum to Full Width

Featured