WinNT/2000 Service Controller

Environment: VC6, Win2000 SP2

This dialog-based VC++ application can be used to control the services in WinNT/2000. To install, follow these steps and the following code:

  1. Open the service control manager and get the handle.
  2. Create the service and get the service handle.
  3. Close the handles.
SC_HANDLE hSCMD = OpenSCManager(NULL,NULL,
                                SC_MANAGER_CREATE_SERVICE);
SC_HANDLE hService = NULL;
if (g_szAcntName[0] == 0)
{
  hService = CreateService(hSCMD, g_szServName, g_szServName, NULL,
    SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,
    SERVICE_ERROR_NORMAL, szBinaryPath, NULL,NULL, NULL,
                                        NULL, NULL);
}
else{
  hService = CreateService(hSCMD, g_szServName, g_szServName, NULL,
    SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,
    SERVICE_ERROR_NORMAL, szBinaryPath, NULL,NULL,
    NULL, g_szAcntName, g_szPassword);
}
CloseServiceHandle(hService);
CloseServiceHandle(hSCMD);

To uninstall, follow these steps and the following code:

  1. Open the service control manager and get the handle.
  2. Open the service and get the service handle.
  3. Delete the service by giving the service handle.
  4. Close the handles.
SC_HANDLE hSCMD = OpenSCManager(NULL,NULL,
                                SC_MANAGER_CREATE_SERVICE);
SC_HANDLE hService = OpenService(hSCMD,g_szServName, DELETE);
DeleteService(hService);
CloseServiceHandle(hService);
CloseServiceHandle(hSCMD);

Downloads

Download demo project - 34 Kb
Download source - 34 Kb


Comments

  • Before CodeGuru full of 1000th "Hello World"

    Posted by Legacy on 12/14/2003 12:00am

    Originally posted by: Before CodeGuru full of 1000th "Hello World"

    Before CodeGuru full of 1000th "Hello World"

    Reply
  • Special???

    Posted by Legacy on 11/14/2002 12:00am

    Originally posted by: Bob

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds