本文整理汇总了C++中atl::CRegKey::DeleteValue方法的典型用法代码示例。如果您正苦于以下问题:C++ CRegKey::DeleteValue方法的具体用法?C++ CRegKey::DeleteValue怎么用?C++ CRegKey::DeleteValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atl::CRegKey
的用法示例。
在下文中一共展示了CRegKey::DeleteValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UninstallService
HRESULT UninstallService()
{
TSAUTO();
ATL::CRegKey key;
LSTATUS lRegResult = key.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost");
if(lRegResult == ERROR_SUCCESS) {
lRegResult = key.DeleteValue(L"ADCleanService");
if(lRegResult != ERROR_SUCCESS) {
TSWARN4CXX("Failed to delete reg value. Key: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost\\ADCleanService. Error: " << lRegResult);
}
key.Close();
}
else {
TSWARN4CXX("Failed to open reg key. Key: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost. Error: " << lRegResult);
}
lRegResult = key.Open(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\services\\ADCleanService");
if(lRegResult == ERROR_SUCCESS) {
lRegResult = key.RecurseDeleteKey(L"Parameters");
if(lRegResult != ERROR_SUCCESS) {
TSWARN4CXX("Failed to delete reg key. Key: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\ADCleanService\\Parameters. Error: " << lRegResult);
}
key.Close();
}
else {
TSWARN4CXX("Failed to open reg key. Key: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\ADCleanService. Error: " << lRegResult);
}
SC_HANDLE schSCManager = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if(schSCManager == NULL) {
DWORD dwOpenError = ::GetLastError();
TSERROR4CXX("OpenSCManager failed. Error: " << dwOpenError);
return HRESULT_FROM_WIN32(dwOpenError);
}
ScopeResourceHandle<SC_HANDLE, BOOL (WINAPI*)(SC_HANDLE)> autoCloseSCManagerHandle(schSCManager, ::CloseServiceHandle);
SC_HANDLE schService = ::OpenService(schSCManager, szServiceName, DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
if(schService == NULL) {
DWORD dwOpenError = ::GetLastError();
TSERROR4CXX("OpenSCManager failed. Error: " << dwOpenError);
return HRESULT_FROM_WIN32(dwOpenError);
}
ScopeResourceHandle<SC_HANDLE, BOOL (WINAPI*)(SC_HANDLE)> autoCloseServiceHandle(schService, ::CloseServiceHandle);
SERVICE_STATUS_PROCESS ssp;
DWORD dwBytesNeeded = 0;
if(!QueryServiceStatusEx(schService, SC_STATUS_PROCESS_INFO, (LPBYTE)&ssp, sizeof(SERVICE_STATUS_PROCESS), &dwBytesNeeded)) {
DWORD dwQueryServiceStatus = ::GetLastError();
TSERROR4CXX("QueryServiceStatusEx failed. Error: " << dwQueryServiceStatus);
return HRESULT_FROM_WIN32(dwQueryServiceStatus);
}
if(ssp.dwCurrentState != SERVICE_STOPPED) {
DWORD dwStartTime = GetTickCount();
DWORD dwTimeout = 30000;
while (ssp.dwCurrentState == SERVICE_STOP_PENDING) {
DWORD dwWaitTime = ssp.dwWaitHint / 10;
if( dwWaitTime < 1000 )
dwWaitTime = 1000;
else if ( dwWaitTime > 10000 )
dwWaitTime = 10000;
Sleep(dwWaitTime);
if(!QueryServiceStatusEx(schService, SC_STATUS_PROCESS_INFO, (LPBYTE)&ssp, sizeof(SERVICE_STATUS_PROCESS), &dwBytesNeeded)) {
DWORD dwQueryServiceStatus = ::GetLastError();
TSERROR4CXX("QueryServiceStatusEx failed. Error: " << dwQueryServiceStatus);
return HRESULT_FROM_WIN32(dwQueryServiceStatus);
}
if(ssp.dwCurrentState == SERVICE_STOPPED) {
TSINFO4CXX("Service Stop Success.");
goto AfterStopLabel;
}
if(GetTickCount() - dwStartTime > dwTimeout) {
TSERROR4CXX("Wait for service stop timeout.");
return E_FAIL;
}
}
if(!ControlService(schService, SERVICE_CONTROL_STOP, (LPSERVICE_STATUS)&ssp)) {
DWORD dwControlServiceError = ::GetLastError();
TSERROR4CXX("ControlService failed. Error: " << dwControlServiceError);
return HRESULT_FROM_WIN32(dwControlServiceError);
}
while ( ssp.dwCurrentState != SERVICE_STOPPED ) {
DWORD dwWaitTime = ssp.dwWaitHint;
if( dwWaitTime < 1000 )
dwWaitTime = 1000;
else if ( dwWaitTime > 10000 )
dwWaitTime = 10000;
//.........这里部分代码省略.........