-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_registry_env.c
More file actions
104 lines (86 loc) · 3.74 KB
/
test_registry_env.c
File metadata and controls
104 lines (86 loc) · 3.74 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
/*
* test_registry_env.c - Test registry environment keys
*
* Compile with: x86_64-w64-mingw32-gcc -o test_registry_env.exe test_registry_env.c -ladvapi32
*/
#include <windows.h>
#include <stdio.h>
int main(void)
{
HKEY hkey;
LONG result;
DWORD type, size;
char buffer[512];
DWORD dword_value;
printf("=== LSW Registry Environment Test ===\n\n");
// Test 1: Windows version
printf("Test 1: Reading Windows version...\n");
result = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
0, KEY_READ, &hkey);
if (result == ERROR_SUCCESS) {
size = sizeof(buffer);
if (RegQueryValueExA(hkey, "ProductName", NULL, &type, (BYTE*)buffer, &size) == ERROR_SUCCESS) {
printf(" ProductName: %s\n", buffer);
}
size = sizeof(buffer);
if (RegQueryValueExA(hkey, "CurrentVersion", NULL, &type, (BYTE*)buffer, &size) == ERROR_SUCCESS) {
printf(" Version: %s\n", buffer);
}
size = sizeof(buffer);
if (RegQueryValueExA(hkey, "CurrentBuildNumber", NULL, &type, (BYTE*)buffer, &size) == ERROR_SUCCESS) {
printf(" Build: %s\n", buffer);
}
RegCloseKey(hkey);
printf(" ✅ Windows version info OK\n\n");
}
// Test 2: Version numbers
printf("Test 2: Reading version numbers...\n");
result = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0, KEY_READ, &hkey);
if (result == ERROR_SUCCESS) {
size = sizeof(dword_value);
if (RegQueryValueExA(hkey, "CurrentMajorVersionNumber", NULL, &type, (BYTE*)&dword_value, &size) == ERROR_SUCCESS) {
printf(" Major Version: %lu\n", dword_value);
}
size = sizeof(dword_value);
if (RegQueryValueExA(hkey, "CurrentMinorVersionNumber", NULL, &type, (BYTE*)&dword_value, &size) == ERROR_SUCCESS) {
printf(" Minor Version: %lu\n", dword_value);
}
size = sizeof(buffer);
if (RegQueryValueExA(hkey, "BuildLab", NULL, &type, (BYTE*)buffer, &size) == ERROR_SUCCESS) {
printf(" BuildLab: %s\n", buffer);
}
RegCloseKey(hkey);
printf(" ✅ Version numbers OK\n\n");
}
// Test 3: System environment
printf("Test 3: Reading system environment...\n");
result = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
0, KEY_READ, &hkey);
if (result == ERROR_SUCCESS) {
size = sizeof(buffer);
if (RegQueryValueExA(hkey, "PROCESSOR_ARCHITECTURE", NULL, &type, (BYTE*)buffer, &size) == ERROR_SUCCESS) {
printf(" Architecture: %s\n", buffer);
}
size = sizeof(buffer);
if (RegQueryValueExA(hkey, "NUMBER_OF_PROCESSORS", NULL, &type, (BYTE*)buffer, &size) == ERROR_SUCCESS) {
printf(" Processors: %s\n", buffer);
}
size = sizeof(buffer);
if (RegQueryValueExA(hkey, "windir", NULL, &type, (BYTE*)buffer, &size) == ERROR_SUCCESS) {
printf(" Windows Directory: %s\n", buffer);
}
size = sizeof(buffer);
if (RegQueryValueExA(hkey, "SystemRoot", NULL, &type, (BYTE*)buffer, &size) == ERROR_SUCCESS) {
printf(" System Root: %s\n", buffer);
}
RegCloseKey(hkey);
printf(" ✅ System environment OK\n\n");
}
printf("=== ALL ENVIRONMENT TESTS PASSED ===\n");
printf("Registry is fully populated with Windows environment!\n");
return 0;
}