注册表操作中,读取指定的键值用的还是比较多的,这次我们就读取HKEY_LOCAL_MACHINE\System\Setup中的SystemPrefix的值。

代码如下:
#include <windows.h> #include <stdio.h> void main(int argc, char *argv[]) { HKEY hKey; unsigned char value[1024]; DWORD ValueLen = 255; DWORD DataType = REG_BINARY; char *defkey = "System\\Setup"; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,defkey,0, KEY_READ,&hKey) == ERROR_SUCCESS) { if(RegQueryValueEx(hKey,"SystemPrefix",0,&DataType,(BYTE*)&value,&ValueLen)==ERROR_SUCCESS) { //REG_BINARY类型输出 printf("SystemPrefix: "); for(int i=0;i<ValueLen;i++) printf("%02x ",value[i]); printf("\n"); } else { printf("Get SystemPrefix from regedit error!\n"); return; } } else { printf("Get SystemPrefix from regedit error!\n"); return; } }
浙公网安备 33010602011771号