1 #include <windows> 2 int main(int argc, char* argv[]) 3 { 4 HKEY hKey; 5 DWORD dwType = REG_SZ; 6 DWORD dwSize = 255;//须指定长度,否则第一次读取RegQueryValueEx不成功,仅返回长度 7 char data[MAX_PATH]; 8 bool ret; 9 10 11 if(RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", &hKey) == ERROR_SUCCESS) 12 cout << "open success" <<endl; 13 14 ret = RegQueryValueEx(hKey,"ProductName", 15 NULL, 16 &dwType, 17 (LPBYTE)data, 18 &dwSize) == ERROR_SUCCESS; 19 20 RegCloseKey(hKey); 21 //ret = wcscmp(data, L"Microsoft Windows XP") == 0; 22 cout << data << endl; 23 24 system("pause"); 25 26 return 0; 27 }
时间: 2024-11-03 21:12:04