• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

windows service

   if i want to run a program of mine  as a windows service who can i do that?
1 Solution
There used to be a service in the NT resource kit that would run any program as a service, but I haven't seen it mentioned anywhere in a long time.

If you are writing the program, then you can just build it as a service from the start.  If you have MS VC++, you can use the ATL COM AppWizard to create a service, and graft your existing code into it.

-- Dan
Dan is right, it is called svrany.exe, and it's hardly available.

As this is the C++ TA, I'd recommend the MS TechNet article "Creating a Simple Win32 Service in C++" - if it was still available on MSDN Online :o)

But, as always, the Google archive is your friend: http://www.google.de/search?q=cache:w_ddLWK68DIC:msdn.microsoft.com/library/techart/msdn_ntservic.htm+%22Creating+a+Simple+Win32+Service+in+C%2B%2B%22&hl=de
BTW, regarding your other Q at http://www.experts-exchange.com/questions/Q.20293636.html - if you want to create a Win9x service, all you have to do is calling 'RegisterServiceProcess()', e.g.

// from http://support.microsoft.com/support/kb/articles/q125/7/14.asp,
// How to Start an Application at Boot Time Under Windows 95
// Last reviewed: September 25, 1995
// Article ID: Q125714

// Define                                   Value               Meaning
#define RSP_SIMPLE_SERVICE        0x00000001     // Registers the process as a
                                                            // simple service process.
#define RSP_UNREGISTER_SERVICE    0x00000000     // Unregisters the process as a
                                                            // service process.

typedef DWORD ( *RSPPROC)   (   DWORD,  DWORD);

RSPPROC RegisterServiceProcess;
HANDLE          g_hSvcDll       =   NULL;

    g_hSvcDll   =   LoadLibrary (   "kernel32.dll");

    if  (   !g_hSvcDll)
            // error

    RegisterServiceProcess  =   ( RSPPROC)  GetProcAddress  (   ( HINSTANCE) g_hSvcDll,

    if  (   !RegisterServiceProcess)
            FreeLibrary (   ( HINSTANCE) g_hSvcDll);
            if  (   !RegisterServiceProcess (   GetCurrentProcessId (),
                    // error

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

U can Use

// Open a handle to the SC Manager database.
SC_HANDLE schSCManager = OpenSCManager(
    NULL,                    // local machine
    NULL,                    // ServicesActive database
    SC_MANAGER_ALL_ACCESS);  // full access rights
if (schSCManager == NULL)
//    MyErrorExit("OpenSCManager");

  SC_HANDLE hService = ::CreateService(
        schSCManager, "URServiceName", "URServiceName",
        "path to ur Exe szFilePath", NULL, NULL, _T("RPCSS\0"), NULL, NULL);

    if (hService == NULL)
        MessageBox(NULL, _T("Couldn't create service"), "Service Name", MB_OK);
        return FALSE;
if (!StartService(
            hService,  // handle to service
            0,           // number of arguments
            NULL) )      // no arguments
        //("Error on StartService");

Also, there was a good article in MSJ that I used when I first tried doing services.  Around Feb of 1997.  I'll have to check my old issues.
This question is current, others below are not.  All of them are awaiting your response.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
POINTS FOR EXPERTS awaiting comments are listed in the link below
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moderator @ Experts Exchange
Thank you for returning and finalizing this.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now