-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWindows Product Key Switcher.cpp
325 lines (283 loc) · 12.5 KB
/
Windows Product Key Switcher.cpp
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#define NOMINMAX
#include <iostream>
#include <string>
#include <algorithm>
#include <Windows.h>
#include <vector>
#include <map>
#include <filesystem>
#include <fmt/format.h>
#include <sstream>
void Windows1110Activation(int option, bool silent, bool activate_windows);
void Windows7Activation(int option, bool silent, bool activate_windows);
void MainMenu(bool silent, bool activate_windows);
bool IsRunAsAdmin() {
BOOL isAdmin = FALSE;
SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY;
PSID adminGroup;
if (AllocateAndInitializeSid(&ntAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0, &adminGroup)) {
if (!CheckTokenMembership(nullptr, adminGroup, &isAdmin)) { isAdmin = FALSE; }
FreeSid(adminGroup);
}
return isAdmin != 0;
}
int Confirmation(
const std::string &text = "Are you sure you want to activate Windows?\nY - activate Windows\nN - back to menu") {
std::string temp;
std::cout << text << std::endl;
std::cout << ">>> ";
std::cin >> temp;
std::transform(temp.begin(), temp.end(), temp.begin(), [](int c) { return std::tolower(c); });
// 0 - yes, -1 - no
return (temp == "y") ? 0 : -1;
}
void GenerateMessage(const std::string &title = "Text", const std::string &arr = "") {
std::cout << title << std::endl;
std::cout << arr << std::endl;
}
void Windows11Menu(bool silent, bool activate_windows) {
std::string choices = R"(
-------------------------------------------
| 1. Windows 11 Home |
| 2. Windows 11 Home Single Language |
| 3. Windows 11 Home N |
-------------------------------------------
| 4. Windows 11 Professional |
| 5. Windows 11 Professional N |
| 6. Windows 11 Professional Education |
| 7. Windows 11 Professional Education N |
-------------------------------------------
| 8. Windows 11 Education |
| 9. Windows 11 Education N |
-------------------------------------------
| 10. Windows 11 Enterprise |
-------------------------------------------
| 11. Windows 11 LTSC 2019/2021 |
| 12. Windows 11 IoT Enterprise LTSC |
-------------------------------------------
)";
GenerateMessage("Select choice", choices);
int value;
std::cout << ">>> ";
std::cin >> value;
Windows1110Activation(value, silent, activate_windows);
}
void Windows10Menu(bool silent, bool activate_windows) {
std::string choices = R"(
-------------------------------------------
| 1. Windows 10 Home |
| 2. Windows 10 Home Single Language |
| 3. Windows 10 Home N |
-------------------------------------------
| 4. Windows 10 Professional |
| 5. Windows 10 Professional N |
| 6. Windows 10 Professional Education |
| 7. Windows 10 Professional Education N |
-------------------------------------------
| 8. Windows 10 Education |
| 9. Windows 10 Education N |
-------------------------------------------
| 10. Windows 10 Enterprise |
-------------------------------------------
| 11. Windows 10 LTSC 2019/2021 |
| 12. Windows 10 IoT Enterprise LTSC |
-------------------------------------------
)";
GenerateMessage("Select choice", choices);
int value;
std::cout << ">>> ";
std::cin >> value;
Windows1110Activation(value, silent, activate_windows);
}
void Windows7Menu(bool silent, bool activate_windows) {
std::string choices = R"(
--------------------------------------------
| 1. Windows 7 Professional |
--------------------------------------------
| 2. Windows 7 Enterprise |
--------------------------------------------)";
GenerateMessage("Select choice", choices);
int value;
std::cout << ">>> ";
std::cin >> value;
Windows7Activation(value, silent, activate_windows);
}
int ActivateWindows(const std::string &productKey, const bool &isLTSC, const bool &isIoTltsc,
const int &i, bool silent, bool activate_windows) {
char buffer[MAX_PATH];
GetModuleFileName(nullptr, buffer, MAX_PATH);
std::string ProgramPath = ((std::string) buffer).substr(0, ((std::string) buffer).find_last_of("\\/"));
if (std::filesystem::exists(ProgramPath + "\\files")) {
if (silent) { std::cout << "Unpacking SKU'S..." << std::endl; }
std::system(fmt::format(
R"(powershell -Command "Expand-Archive '{}\files\{}.zip' -Force -DestinationPath $env:windir\system32\spp\tokens\skus\ -erroraction 'silentlycontinue')",
ProgramPath,
(i == 1) ? "spp10" : (i == 2) ? "spp8.1" : (i == 4) ? "spp7" : "").c_str());
if (silent) { std::cout << "Registering SKU's, please wait..." << std::endl; }
std::system(R"(cscript.exe //Nologo //B C:\Windows\System32\slmgr.vbs /rilc)");
} else {
std::cout << "Couldn't find files directory with needed files, "
<< "please download program from github "
<< "https://github.com/Snaky1a/Windows-Product-Key-Switcher/releases"
<< std::endl;
return -1;
}
if (isLTSC) {
std::system(R"(cscript.exe //Nologo //B C:\Windows\System32\slmgr.vbs /upk)");
std::system(R"(cscript.exe //Nologo //B C:\Windows\System32\slmgr.vbs /ckms)");
std::system(R"(cscript.exe //Nologo //B C:\Windows\System32\slmgr.vbs /cpky)");
return 0;
}
if (std::system(fmt::format(R"(cscript.exe //Nologo //B C:\Windows\System32\slmgr.vbs /ipk {})",
productKey).c_str()) == 0) {
if (silent) { std::cout << "Product key installed successfully." << std::endl; }
}
if (!isIoTltsc) {
if (!activate_windows) {
if (Confirmation("Do you want activate Windows with Online KMS?"
"\nY - yes\nN - I want to activate myself / "
"I will activate it later") == 0) {
std::system(R"(cscript.exe //Nologo //B C:\Windows\System32\slmgr.vbs /skms kms.loli.best)");
std::system(R"(cscript.exe //Nologo //B C:\Windows\System32\slmgr.vbs /ato)");
}
} else {
std::system(R"(cscript.exe //Nologo //B C:\Windows\System32\slmgr.vbs /skms kms.loli.best)");
std::system(R"(cscript.exe //Nologo //B C:\Windows\System32\slmgr.vbs /ato)");
}
} else {
if (!activate_windows) {
if (Confirmation("Do you want activate Windows with HWID activation (only for IoT LTSC)?"
"\nY - yes\nN - I want to activate myself / "
"I will activate it later") == 0) {
std::system(("\"" + ProgramPath + R"(\files\IOT_LTSC_ACTIVATION.cmd")").c_str());
}
} else {
std::system(("\"" + ProgramPath + R"(\files\IOT_LTSC_ACTIVATION.cmd")").c_str());
}
}
return 0;
}
void Windows1110Activation(int option, bool silent, bool activate_windows) {
// Windows 10/11
std::map<std::string, std::string> w10_keys = {
{"1", "TX9XD-98N7V-6WMQ6-BX7FG-H8Q99"}, // Home
{"2", "7HNRX-D7KGG-3K4RQ-4WPJ4-YTDFH"}, // Home Single Language
{"3", "3KHY7-WNT83-DGQKR-F7HPR-844BM"}, // Home N
{"4", "W269N-WFGWX-YVC9B-4J6C9-T83GX"}, // Pro
{"5", "MH37W-N47XK-V7XM9-C7227-GCQG9"}, // Pro N
{"6", "6TP4R-GNPTD-KYYHQ-7B7DP-J447Y"}, // Pro Edu
{"7", "YVWGF-BXNMC-HTQYQ-CPQ99-66QFC"}, // Pro Edu N,
{"8", "NW6C2-QMPVW-D7KKK-3GKT6-VCFB2"}, // Edu
{"9", "2WH4N-8QGBV-H22JP-CT43Q-MDWWJ"}, // Edu N
{"10", "NPPR9-FWDCX-D2C8J-H872K-2YT43"}, // Enterprise
{"11", "M7XTQ-FN8P6-TTKYV-9D4CC-J462D"}, // LTSC 2021
{"12", "QPM6N-7J2WJ-P88HH-P3YRH-YY74H"}, // IoT LTSC
};
if (Confirmation() == -1) { MainMenu(silent, activate_windows); }
else {
auto res = w10_keys.find(std::to_string(option));
if (res != w10_keys.end()) {
ActivateWindows(res->second, (option == 11), (option == 12), 1, silent, activate_windows);
}
}
}
void Windows7Activation(int option, bool silent, bool activate_windows) {
// Windows 10/11
std::map<std::string, std::string> w10_keys = {
{"1", "FJ82H-XT6CR-J8D7P-XQJJ2-GPDD4"}, // Professional
{"2", "33PXH-7Y6KF-2VJC9-XBBR8-HVTHH"}, // Enterprise
};
if (Confirmation() == -1) { MainMenu(silent, activate_windows); }
else {
auto res = w10_keys.find(std::to_string(option));
if (res != w10_keys.end()) { ActivateWindows(res->second, false, false, 4, silent, activate_windows); }
}
}
void MainMenu(bool silent, bool activate_windows) {
std::system("cls");
std::string menu = R"(
-----------------------
| 1. Windows 11 menu |
| 2. Windows 10 menu |
| 3. Windows 8 menu |
| 4. Windows 7 menu |
-----------------------)";
int value;
GenerateMessage("Select choice", menu);
std::cout << ">>> ";
std::cin >> value;
if (value == 1) { Windows11Menu(silent, activate_windows); }
else if (value == 2) { Windows10Menu(silent, activate_windows); }
else if (value == 4) { Windows7Menu(silent, activate_windows); }
else { std::cout << "This option is not implemented. Wait new release! :)" << std::endl; }
std::cout << "Press any key to exit from program..." << std::endl;
std::cin.ignore();
std::cin.get();
exit(0);
}
std::vector<std::string> GetFlagsFromCommandLine(int argc, char *argv[]) {
std::vector<std::string> flags;
for (int i = 1; i < argc; ++i) { flags.emplace_back(argv[i]); }
return flags;
}
int main(int argc, char *argv[]) {
if (IsRunAsAdmin()) {
int result = std::system(std::string(
"powershell -Command \"$PSVersionTable.PSVersion.Major -ge 5\" | findstr False >NUL || exit /B 1").c_str());
// 0 - powershell 5+ needed
if (result == 0) {
std::cout << "For using this program, you need install Powershell 5.1 version or higher"
"\nFollow this link: https://learn.microsoft.com/en-us/powershell/scripting"
"/windows-powershell/wmf/setup/install-configure?view=powershell-5.1#install"
"-wmf-51-for-windows-server-2008-r2-and-windows-7"
<< std::endl;
std::cout << "Press any key to exit from program..." << std::endl;
std::cin.ignore();
std::cin.get();
exit(0);
}
std::vector<std::string> flags = GetFlagsFromCommandLine(argc, argv);
bool silent = false;
bool activate_windows = false;
for (const std::string &flag: flags) {
if (flag == "--silent" || flag == "-s" || flag == "/silent" || flag == "/s") {
silent = true;
}
if (flag == "--activate" || flag == "-act" || flag == "/activate" || flag == "/act") {
activate_windows = true;
}
if (flag == "--help" || flag == "/help") {
std::cout
<< "Program Options:\noption(s) name\t\t\t\tdescription\n--silent (or -s, /silent, /s)\t\tdo not show information, "
<< "only select windows version and edition.\n--activate (or -act, /activate, "
<< "/act)\tactivate windows without confirmation."
<< std::endl;
std::cout << "Press any key to exit from program..." << std::endl;
std::cin.ignore();
std::cin.get();
exit(0);
}
std::cout << "Flag: " << flag << std::endl;
}
MainMenu(silent, activate_windows);
} else {
if (Confirmation("Run program with administrative rights\nY - Run\nN - Exit") != -1) {
char buffer[MAX_PATH];
GetModuleFileName(nullptr, buffer, MAX_PATH);
std::stringstream ss;
ss << "powershell -Command \"Start-Process -filepath '" << buffer;
if (argc > 1) {
ss << "' -ArgumentList ";
std::string arguments;
for (int i = 1; i < argc; ++i) {
arguments += " \"" + std::string(argv[i]) + "\"";
}
ss << "'" << arguments;
}
ss << "' -Verb RunAs\"";
std::system(ss.str().c_str());
} else { exit(0); }
}
}