-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetRegedit.cpp
More file actions
144 lines (138 loc) · 3.44 KB
/
GetRegedit.cpp
File metadata and controls
144 lines (138 loc) · 3.44 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// GetManID.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <string>
#include <winnt.h>
using namespace std;
//HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS
void ReadRegValue(const HKEY hkey, const std::string& strKey)
{
HKEY hkResult;
cout << strKey << endl;
LSTATUS lRet = RegOpenKeyEx(hkey, strKey.c_str(), 0, KEY_READ, &hkResult);
if (ERROR_SUCCESS == lRet)
{
DWORD cSubKeys = 0;
DWORD cbMaxSubKeyLen = 0;
DWORD cbMaxClassLen = 0;
DWORD cValues = 0;
DWORD cbMaxValueNameLen = 0;
DWORD cbMaxValueLen = 0;
DWORD cbSecurityDescriptor = 0;
FILETIME ftLastWriteTime;
lRet = RegQueryInfoKey(
hkResult,
nullptr,
nullptr,
0,
&cSubKeys,
&cbMaxSubKeyLen,
&cbMaxClassLen,
&cValues,
&cbMaxValueNameLen,
&cbMaxValueLen,
&cbSecurityDescriptor,
&ftLastWriteTime
);
if (ERROR_SUCCESS == lRet)
{
if (cSubKeys > 0)
{
for (DWORD dwSubkey = 0; dwSubkey < cSubKeys; ++dwSubkey)
{
DWORD dwKeySize = cbMaxSubKeyLen + 1;
TCHAR* lpKeyName = new TCHAR[dwKeySize];
string subKey = strKey;
memset(lpKeyName, 0, dwKeySize * sizeof(TCHAR));
lRet = RegEnumKeyEx(hkResult, dwSubkey, lpKeyName, &dwKeySize, nullptr, nullptr, nullptr, nullptr);//读取键值
if (ERROR_SUCCESS == lRet)
{
if (!subKey.empty())
{
subKey.append("\\");
}
subKey.append(lpKeyName);
delete[] lpKeyName;
ReadRegValue(hkey, subKey);
}
else
{
delete[] lpKeyName;
}
}
}
if (cValues > 0)
{
cout << "\t\t" << "Name" << "\t" << " Type" << "\t" << " Data" << endl;
}
for (DWORD dwIndex = 0; dwIndex < cValues; ++dwIndex)
{
DWORD dwNameSize = cbMaxValueNameLen + 1;
TCHAR* lpValueName = new TCHAR[dwNameSize];
memset(lpValueName, 0, dwNameSize * sizeof(TCHAR));
DWORD Type = 0;
DWORD dwDataSize = cbMaxValueLen + 1;
LPBYTE lpData = new BYTE[dwDataSize];
memset(lpData, 0, dwDataSize * sizeof(BYTE));
RegEnumValue(hkResult, dwIndex, lpValueName, &dwNameSize, nullptr, &Type, lpData, &dwDataSize);//读取键值
if (dwNameSize > 0)
{
cout << "\t\t" << lpValueName << "\t" << Type << "\t" << lpData << endl;
}
delete[] lpValueName;
delete[] lpData;
}
}
}
}
#define MAKESTR(s) #s,s
void main(int argc, char* const* argv)
{
if (argc != 2)
{
cout << "Usage: HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System";
exit(1);
}
static struct
{
std::string strHkey;
HKEY hkey;
}Str2Key[] = {
MAKESTR(HKEY_CLASSES_ROOT),
MAKESTR(HKEY_CURRENT_USER),
MAKESTR(HKEY_LOCAL_MACHINE),
MAKESTR(HKEY_USERS),
MAKESTR(HKEY_PERFORMANCE_DATA),
MAKESTR(HKEY_PERFORMANCE_TEXT),
MAKESTR(HKEY_PERFORMANCE_NLSTEXT),
#if (WINVER >= 0x0400)
MAKESTR(HKEY_CURRENT_CONFIG),
MAKESTR(HKEY_CURRENT_CONFIG),
MAKESTR(HKEY_CURRENT_USER_LOCAL_SETTINGS),
#endif
"",0 };
std::string strArgs = argv[1];
std::string strHkey = strArgs;
size_t pos = strArgs.find_first_of('\\');
std::string strSubKey;
if (string::npos != pos)
{
strHkey = strArgs.substr(0, pos);
strSubKey = strArgs.substr(pos + 1);
}
HKEY hkey = 0;
for (int i = 0; !Str2Key[i].strHkey.empty(); ++i)
{
if (Str2Key[i].strHkey == strHkey)
{
hkey = Str2Key[i].hkey;
break;
}
}
if (hkey)
{
ReadRegValue(hkey, strSubKey);
}
}