General Service Control (IIS Control Example)

zhaozj2021-02-16  65

Void cxxxdlg :: serviceUn ()

{

Service_status ssstatus;

// Get the handle of the ServiceControl Manager

SC_HANDLE SHSERVICEMANAGER = OPENSCMANAGER (NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);

/ / Then get the handle of the user wants to check the service

SC_Handle ShdefineService = OpenService (SHSERVICEMANAGER, "W3SVC", Service_All_Access);

IF ((QueryService, & SSSTATUS) == 0)

AFXMessageBox ("Uncleary Service Status", MB_ICONInformation);

// The following code is used to check if the service is stopped, if stopped, open this service

SC_HANDLE STSERVICE;

IF (SSSTATUS.DWCURRENTSTATE == Service_Stopped)

{

// afxMessageBox ("Start IIS", MB_ICONITION);

StService = OpenService (SHSERVICEMANAGER, "W3SVC", Service_Start | Generic_execute);

StartService (StService, 0, NULL);

ClosESERVICEHANDE (Stservice);

}

Else

{

// afXMessageBox ("Stop IIS", MB_ICONITION);

StService = OpenService (SHSERVICEMANAGER, "W3SVC", service_stop | generic_execute);

ControlService (StService, Service_Control_stop, & ssstatus);

ClosESERVICEHANDE (Stservice);

}

ClosEServiceHandle (ShdefineService);

ClosESERVICEHANDLE (SHSERVICEMANAGER);

}

转载请注明原文地址:https://www.9cbs.com/read-15885.html

New Post(0)