描述:
不知怎样检测一个服务是否存在,又需要些什么信息?
解决方案1:
需要知道服务的名称
hSCDB=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if(!hSCDB)
{
throw "无法打开服务控制器,无法卸载服务。";
}
SC_HANDLE h1=OpenService(hSCDB,SSCESERVER_SERVICE_NAME,SERVICE_ALL_ACCESS);
if(!h1)
{
//找不到服务
throw "打开服务失败,无法卸载服务。";
}
SC_HANDLE OpenSCManager(
LPCTSTR lpMachineName, // computer name
LPCTSTR lpDatabaseName, // SCM database name
DWORD dwDesiredAccess // access type
);
BOOL EnumServicesStatus(
SC_HANDLE hSCManager, // handle to SCM database
DWORD dwServiceType, // service type
DWORD dwServiceState, // service state
LPENUM_SERVICE_STATUS lpServices, // status buffer
DWORD cbBufSize, // size of status buffer
LPDWORD pcbBytesNeeded, // buffer size needed
LPDWORD lpServicesReturned, // number of entries returned
LPDWORD lpResumeHandle // next entry
);