Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Programming Services in C++

Posted on 2009-05-14
4
Medium Priority
?
267 Views
Last Modified: 2012-05-07
I need a way to change the service parameters like SERVICE_EXIT_CODE value to 2 other than 0.

Plz see the description below.

In command prompt by typing
sc query themes

Displays:
SERVICE_NAME: themes
        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

I want to change these parameters(ex: WIN32_EXIT_CODE value to -223 or any other value).
FYI: (There is a structure SERVICE_STATUS which takes care of these values.)
I need a program in C++  to achieve it.
0
Comment
[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
  • 2
4 Comments
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24393087
The service exit code is the return value of an service when terminating. The service can set it to the SERVICE_STATUS structure associated with the service by calling SetServiceStatus passing the handle to the updated structure. If you would write 2 or -223 to the dwCurrentState member of that structure, the Service Control Manager surely would reflect that status.
0
 
LVL 9

Author Comment

by:Subrat (C++ windows/Linux)
ID: 24393338
Can u plz send me the code to do that.
Thanks
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 2000 total points
ID: 24393937
Below is sample code how a service sets its current status.  

The full sample can be found at http://support.microsoft.com/kb/201349/en-us

If your sservice stops or was stopped by SCM (Service Control Manager) you would set your status to the code you want. Try to not match to status code which have a different meaning, e. g. SERVICE_START_PENDING

Here are the codes for predefined status values

//
// Service State -- for CurrentState
//
#define SERVICE_STOPPED                0x00000001
#define SERVICE_START_PENDING          0x00000002
#define SERVICE_STOP_PENDING           0x00000003
#define SERVICE_RUNNING                0x00000004
#define SERVICE_CONTINUE_PENDING       0x00000005
#define SERVICE_PAUSE_PENDING          0x00000006
#define SERVICE_PAUSED                 0x00000007


      // Register the ServiceHandler() function to receive control requests.
      hService = RegisterServiceCtrlHandler( SERVICE_NAME,
            ServiceHandler );
 
      // Set service status to start pending.
      ss.dwCurrentState = SERVICE_START_PENDING;
      ss.dwCheckPoint = 1; 
      ss.dwWaitHint = 500;
      SetServiceStatus( hService, &ss );
 
      // TODO: add additional initialization code here.
 
      // set service status to running
      ss.dwCurrentState = SERVICE_RUNNING;
      ss.dwCheckPoint = ss.dwWaitHint = 0;   
      SetServiceStatus( hService, &ss );

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

604 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