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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds