CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    Windows Service in Win7 would be nice ... but ...

    Through courtesy of:

    A basic Windows service in C++ (CppWindowsServ​ice)
    This code sample demonstrates creating a basic Windows Service application in VC++
    http://code.msdn.microsoft.com/windo...rvice-cacf4948

    I downloaded and built the above service on Win7 Ultimate (64bi) VS 2010. All seemed to go well and I was able to install the service using the Command Prompt. However, attempting to start the service was not possible, even when opening the Control Panel/Administrative Tools/Services as Administrator. Attempts to use the Start command were invariably met with:

    Windows could not start the CppWindowService Sample Service service on Local COmputer.

    Error 2: The system cannot find the file specified.
    Oddly, looking at the Properties Page of the service, the path of the service is correct.

    Please advise what I am doing wrong or what I am missing.

    Thanks
    mpliam

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

    Re: Windows Service in Win7 would be nice ... but ...

    IMO, easiest way to create a C++ based Windows Service is to use the ATL project and #define _ATL_NO_COM_SUPPORT if you don't want the service to host COM.

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Windows Service in Win7 would be nice ... but ...

    Oddly, looking at the Properties Page of the service, the path of the service is correct.
    The path may be correct but roamed at the same time. To start getting known with programming services I would recommend WINXP.
    Best regards,
    Igor

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Windows Service in Win7 would be nice ... but ...

    Just built that sample in VS2010, installed and started the service with no problem in Windows 7 64-bit. What am I doing wrong?
    Best regards,
    Igor

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Windows Service in Win7 would be nice ... but ...

    if your path is:
    - a network path
    - a SUBSTed path
    - a Junctioned path
    - a path that lies under the user profile
    - ...

    Services run in the service context with a different user account that you are typically "SYSTEM" or "LOCAL SYSTEM", that system account may not have the same network mappings, substs, junctions, or may not have access in user folders.

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

    Re: Windows Service in Win7 would be nice ... but ...

    Quote Originally Posted by OReubens View Post
    if your path is:
    - a network path
    - a SUBSTed path
    - a Junctioned path
    - a path that lies under the user profile
    - ...

    Services run in the service context with a different user account that you are typically "SYSTEM" or "LOCAL SYSTEM", that system account may not have the same network mappings, substs, junctions, or may not have access in user folders.
    For this reason, I generally setup my service code to be able to be run as a service and as a regular user. That way, if the service can function as a user, but not as a service, it's generally a permissions issue (which I can confirm by running the service account as a user). Not solving world hunger here, but just a simple technique that makes developing services easier.

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