1、安装
VOID InstallService(LPCTSTR lpName, LPCTSTR lpPath)
{
SC_HANDLE schSCManager;
SC_HANDLE schService;
schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (schSCManager)
{
schService = CreateService(
schSCManager,
lpName,
lpName,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
lpPath,
NULL,
NULL,
NULL,
NULL,
NULL);
if (schService)
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
}
}
2、移除
VOID RemoveService(LPCTSTR lpName)
{
SC_HANDLE schSCManager;
SC_HANDLE schService;
schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (schSCManager)
{
schService = OpenService(schSCManager, lpName, DELETE);
if(schService)
{
DeleteService(schService);
CloseServiceHandle(schService);
}
CloseServiceHandle(schSCManager);
}
}