#pragma comment(lib,"advapi32")
#include <stdio.h>
#include <windows.h>
#include <tchar.h>
int main() {
LPCTSTR Regkey = _T("Software\\Microsoft\\Windows NT\\CurrentVersion");
DWORD dwInsTime = 0;
DWORD dwType = REG_DWORD;
DWORD cbData = sizeof(DWORD);
LPVOID lpMsgBuf;
HKEY hKey;
LONG r;
r=RegOpenKeyEx(HKEY_LOCAL_MACHINE, Regkey, 0, KEY_ALL_ACCESS, &hKey);
if (ERROR_SUCCESS==r) {
r=RegQueryValueEx(hKey, _T("InstallDate"), NULL, &dwType, (PBYTE)&dwInsTime, &cbData);
if (ERROR_SUCCESS==r) {
_tprintf(_T("%s %s:0x%08x\n"),_T("Software\\Microsoft\\Windows NT\\CurrentVersion"),_T("InstallDate"),dwInsTime);
RegCloseKey(hKey);
return 0;
} else {
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,r,0,(LPTSTR)&lpMsgBuf,0,NULL);
_tprintf(_T("RegQueryValueEx Error:0x%08x,%s\n"),r,lpMsgBuf);
LocalFree( lpMsgBuf );
RegCloseKey(hKey);
return 2;
}
} else {
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,r,0,(LPTSTR)&lpMsgBuf,0,NULL);
_tprintf(_T("RegOpenKeyEx Error:0x%08x,%s\n"),r,lpMsgBuf);
LocalFree( lpMsgBuf );
return 1;
}
}
//Software\Microsoft\Windows NT\CurrentVersion InstallDate:0x4d084f57
//
正确读取REG_DWORD键值
最新推荐文章于 2023-04-22 18:23:46 发布