c++ 读取注册表,读取服务安装位置 123456789101112131415161718192021222324252627282930313233343536373839404142434445bool DogWork::GetServicePath(const TCHAR* name, mm::mstring & path){ bool res = false;#ifdef WIN32 // GetServiceDisplayName() mm::mstring lpSubKey(TEXT("SYSTEM\\CurrentControlSet\\services\\")); lpSubKey += name; do { HKEY hKey; //HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\testdog DWORD lResult = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey.c_str(), 0, KEY_READ, &hKey); if (lResult != ERROR_SUCCESS) { if (lResult == ERROR_FILE_NOT_FOUND) { LOG_ERROR("Key not found."); break; } else { LOG_ERROR("Error opening key."); break; } break; } TCHAR dwValue[4096]; DWORD dwSize = 4096; DWORD dwType = REG_EXPAND_SZ; if (::RegQueryValueEx(hKey, TEXT("ImagePath"), 0, &dwType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS) { LOG_ERROR("RegQueryValueEx ImagePath."); RegCloseKey(hKey); break; } RegCloseKey(hKey); path= dwValue; res = true; } while (0);#endif return res;}