1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
   |  bool DogWork::GetServicePath(const TCHAR* name, mm::mstring & path) {     bool res = false; #ifdef WIN32          mm::mstring lpSubKey(TEXT("SYSTEM\\CurrentControlSet\\services\\"));     lpSubKey += name;     do     {         HKEY hKey;                  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; }
 
  |