Solved

windows service

Posted on 2002-04-25
7
264 Views
Last Modified: 2008-03-06
Hi,
   if i want to run a program of mine  as a windows service who can i do that?
0
Comment
Question by:ttsenis
7 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 6969430
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 6969469
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
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6969489
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,
                                                                "RegisterServiceProcess"
                                                            );

    if  (   !RegisterServiceProcess)
        {
            FreeLibrary (   ( HINSTANCE) g_hSvcDll);
        }
     else
        {
            if  (   !RegisterServiceProcess (   GetCurrentProcessId (),
                                                RSP_SIMPLE_SERVICE
                                            )
                )
                {
                    // error
                }
        }

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:job_s
ID: 6971050
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");
return;
}

  SC_HANDLE hService = ::CreateService(
        schSCManager, "URServiceName", "URServiceName",
SERVICE_ALL_ACCESS,SERVICE_INTERACTIVE_PROCESS|SERVICE_WIN32_OWN_PROCESS ,
        SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
        "path to ur Exe szFilePath", NULL, NULL, _T("RPCSS\0"), NULL, NULL);

    if (hService == NULL)
    {
        ::CloseServiceHandle(schSCManager);
        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");
    }

regards
Job_s
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 6971330
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.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6979365
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.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
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.
http://www.experts-exchange.com/questions/Q.11528958.html
http://www.experts-exchange.com/questions/Q.20027069.html
http://www.experts-exchange.com/questions/Q.20109793.html
http://www.experts-exchange.com/questions/Q.20109788.html
http://www.experts-exchange.com/questions/Q.20284952.html
http://www.experts-exchange.com/questions/Q.20289305.html
http://www.experts-exchange.com/questions/Q.20289308.html
http://www.experts-exchange.com/questions/Q.20293636.html
http://www.experts-exchange.com/questions/Q.20293637.html



*****  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
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
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.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6980542
Thank you for returning and finalizing this.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question