C中是否有API可用于检查文件索引打开还是关闭?
代码受到赞赏。
最佳答案
WMI在C ++中很痛苦,但是本机Service API非常干净。
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
if(hSCManager)
{
SC_HANDLE hService = OpenService(hSCManager, _T("ServiceNameGoesHere"), SERVICE_QUERY_STATUS);
if(hService)
{
// service is installed
SERVICE_STATUS ServiceStatus;
if(ServiceQueryStatus(hService, &ServiceStatus))
{
// service is running
// get current state from ServiceStatus.dwCurrentState
}
else if(GetLastError() == ERROR_SERVICE_NOT_ACTIVE)
{
// service is not running
}
else
{
// error
}
CloseServiceHandle(hService);
hService = NULL;
}
else if(GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)
{
// service is not installed
}
else
{
// error
}
CloseServiceHandle(hSCManager);
hSCManager = NULL;
}
else
{
// error
}
关于c - 如何检查Windows文件索引打开还是关闭,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2238606/