?
Solved

windows service

Posted on 2002-04-25
7
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 800 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

771 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