Solved

windows service

Posted on 2002-04-25
7
259 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now