Solved

windows service

Posted on 2002-04-25
7
257 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 3

Expert Comment

by:job_s
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for returning and finalizing this.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 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…

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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now