-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAntiBloatware.cpp
More file actions
491 lines (447 loc) · 21.6 KB
/
Copy pathAntiBloatware.cpp
File metadata and controls
491 lines (447 loc) · 21.6 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
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/*
* Windows Debloater (safe subset)
* --------------------------------
* Disables a curated list of non-essential background Windows services and
* scheduled tasks. Anything that is commonly noticeable in daily use, or
* that could actually break something, is deliberately left ALONE:
* - Bluetooth (bthserv, BthHFSrv, BTAGService)
* - Microsoft Store / UWP core (AppXSVC, ClipSVC, StateRepository, tiledatamodelsvc)
* - Notifications (WpnService, WpnUserService)
* - Diagnostics used by Windows troubleshooters (DPS, WdiServiceHost/SystemHost)
* - Windows Hello / biometrics (WbioSrvc, NgcSvc)
* - System Restore / Shadow Copy (VSS, SWPRV) -- ironic to break the safety net
* - Themes (breaks the whole visual style, very noticeable)
* - Windows Update Medic Service (protected, and needed for updates)
* - License Manager (Store licensing / activation checks)
* - Camera Frame Server (breaks Zoom/Teams/Skype/Camera app)
* - Touch keyboard service (needed on touchscreens/tablets)
* - Capability Access Manager (camera/mic/location permission broker)
* - Clipboard User Service (breaks clipboard sync/history, sometimes copy-paste)
* - System Events Broker (core shell/UWP event plumbing)
* - Device Setup Manager / Device Association (new-hardware driver install & pairing)
* - Virtual Disk service (Disk Management VHD/partition operations)
* - HidSvc (custom keyboard/mouse hotkeys on branded peripherals)
* - Parental Controls monitor (in case Family Safety is configured)
*
* The program prints every single step, creates an optional System Restore
* point first, and prints a full summary (including what it skipped and why)
* at the end.
*
* Build (MSVC "x64 Native Tools Command Prompt"):
* cl /EHsc /std:c++17 debloater.cpp /link shell32.lib advapi32.lib
*
* Build (MinGW-w64):
* g++ -std=c++17 -O2 -o debloater.exe debloater.cpp -lshell32 -ladvapi32
*
* Run the resulting .exe. It will ask to relaunch itself as Administrator
* if it isn't already elevated.
*/
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <shellapi.h>
#include <cstdio>
#include <cwchar>
#include <iostream>
#include <string>
#include <vector>
#pragma comment(lib, "shell32.lib")
#pragma comment(lib, "advapi32.lib")
// ---------------------------------------------------------------------------
// Minimal System Restore API declarations (avoids depending on srrestoreptapi.h,
// which isn't shipped with every compiler/SDK combo). Loaded dynamically below.
// ---------------------------------------------------------------------------
#define DESCRIPTION_LEN 256
#define BEGIN_SYSTEM_CHANGE 100
#define END_SYSTEM_CHANGE 101
#define APPLICATION_INSTALL 0
typedef struct _RESTOREPOINTINFOW {
DWORD dwEventType;
DWORD dwRestorePtType;
INT64 llSequenceNumber;
WCHAR szDescription[DESCRIPTION_LEN];
} RESTOREPOINTINFOW, * PRESTOREPOINTINFOW;
typedef struct _STATEMGRSTATUS {
DWORD nStatus;
INT64 llSequenceNumber;
} STATEMGRSTATUS, * PSTATEMGRSTATUS;
typedef BOOL(WINAPI* SRSetRestorePointW_t)(PRESTOREPOINTINFOW, PSTATEMGRSTATUS);
// ---------------------------------------------------------------------------
// Data model
// ---------------------------------------------------------------------------
struct SvcEntry {
std::string id; // service short (registry) name, used with sc.exe
std::string display; // human readable name
};
struct Section {
std::string title;
std::vector<SvcEntry> services;
};
struct TaskEntry {
std::string path; // Task Scheduler path, used with schtasks.exe
std::string display;
};
struct SkipEntry {
std::string id;
std::string reason;
};
struct Stats {
int servicesDisabled = 0;
int servicesFailed = 0;
int servicesNotFound = 0;
int tasksDisabled = 0;
int tasksFailed = 0;
int tasksNotFound = 0;
} g_stats;
static INT64 g_restoreSeq = 0;
static bool g_restorePointStarted = false;
// ---------------------------------------------------------------------------
// Curated "safe to disable" list
// ---------------------------------------------------------------------------
static const std::vector<Section> g_serviceSections = {
{ "Telemetry & Error Reporting", {
{"DiagTrack", "Connected User Experiences and Telemetry"},
{"dmwappushservice", "WAP Push Message Routing Service"},
{"WerSvc", "Windows Error Reporting Service"},
}},
{ "Xbox / Gaming Background Services", {
{"XblAuthManager", "Xbox Live Auth Manager"},
{"XblGameSave", "Xbox Live Game Save"},
{"XboxGipSvc", "Xbox Accessory Management Service"},
{"XboxNetApiSvc", "Xbox Live Networking"},
{"BcastDVRUserService","GameDVR and Broadcast User Service"},
}},
{ "Sensors & Location", {
{"SensorService", "Sensor Service"},
{"SensrSvc", "Sensor Monitoring Service"},
{"SpatialDataService", "Spatial Data Service"},
{"lfsvc", "Geolocation Service"},
}},
{ "Enterprise / Virtualization (rarely used on home PCs)", {
{"AppVClient", "Microsoft App-V Client"},
{"UevAgentService", "User Experience Virtualization Service"},
{"MsKeyboardFilter", "Microsoft Keyboard Filter"},
{"WorkFolders", "Work Folders"},
{"ScDeviceEnum", "Smart Card Device Enumeration Service"},
{"SCPolicySvc", "Smart Card Removal Policy"},
{"CertPropSvc", "Certificate Propagation"},
}},
{ "Backup / Caching (only matters if you use these features)", {
{"fhsvc", "File History Service"},
{"CscService", "Offline Files"},
}},
{ "Minor Visual Extras", {
{"WcsPlugInService", "Windows Color System"},
}},
{ "Legacy Peer-to-Peer Protocols (dead in practice)", {
{"PNRPsvc", "Peer Name Resolution Protocol"},
{"p2psvc", "Peer Networking Grouping"},
{"p2pimsvc", "Peer Networking Identity Manager"},
{"PNRPAutoReg", "PNRP Machine Name Publication Service"},
{"AJRouter", "AllJoyn Router Service"},
}},
{ "Performance Logging & Monitoring", {
{"pla", "Performance Logs & Alerts"},
{"wmiApSrv", "WMI Performance Adapter"},
{"Wecsvc", "Windows Event Collector"},
}},
{ "Microsoft Edge Background Updaters", {
{"edgeupdate", "Microsoft Edge Update Service"},
{"edgeupdatem", "Microsoft Edge Update Service (medium)"},
{"MicrosoftEdgeElevationService", "Microsoft Edge Elevation Service"},
}},
{ "Imaging (scanners)", {
{"stisvc", "Windows Image Acquisition (WIA)"},
}},
{ "Phone / Maps / Wallet", {
{"PhoneSvc", "Phone Service"},
{"MapsBroker", "Downloaded Maps Manager"},
{"WalletService","WalletService"},
}},
{ "Misc Background Drainers", {
{"SysMain", "SysMain (Superfetch)"},
{"RpcLocator", "RPC Locator"},
{"SNMP", "SNMP Service"},
{"SNMPTRAP", "SNMP Trap"},
{"wisvc", "Windows Insider Service"},
{"TrkWks", "Distributed Link Tracking Client"},
{"KtmRm", "KtmRm for Distributed Transaction Coordinator"},
{"QWAVE", "Quality Windows Audio Video Experience"},
{"WinRM", "Windows Remote Management (WS-Management)"},
{"smphost", "Storage Spaces SMP"},
{"PimIndexMaintenanceSvc", "Contact Data"},
{"DsSvc", "Data Sharing Service"},
{"EntAppSvc", "Enterprise App Management Service"},
{"GraphicsPerfSvc", "GraphicsPerfSvc"},
}},
};
static const std::vector<TaskEntry> g_tasks = {
{"\\Microsoft\\Windows\\.NET Framework\\.NET Framework NGEN v4.0.30319", ".NET Framework NGEN v4.0.30319"},
{"\\Microsoft\\Windows\\.NET Framework\\.NET Framework NGEN v4.0.30319 64", ".NET Framework NGEN v4.0.30319 64"},
{"\\Microsoft\\Windows\\Maintenance\\WinSAT", "WinSAT Performance Assessment"},
{"\\Microsoft\\Office\\Office Automatic Updates 2.0", "Microsoft Office ClickToRun Updates"},
{"\\GoogleUpdateTaskMachineCore", "Google Update Task (Core)"},
{"\\GoogleUpdateTaskMachineUA", "Google Update Task (UA)"},
{"\\Adobe Acrobat Update Task", "Adobe Acrobat Update Task"},
{"\\MicrosoftEdgeUpdateTaskMachineCore", "Microsoft Edge Core Update Scheduler"},
{"\\MicrosoftEdgeUpdateTaskMachineUA", "Microsoft Edge UA Update Scheduler"},
{"\\Microsoft\\Windows\\Windows Error Reporting\\QueueReporting", "Windows Error Reporting Queue"},
{"\\Microsoft\\Windows\\Network Connected Devices Auto-Setup\\Network Connected Devices Auto-Setup",
"Network Connected Devices Auto-Setup"},
};
static const std::vector<SkipEntry> g_skipped = {
{"AppXSVC / ClipSVC / StateRepository / tiledatamodelsvc", "Core to the Microsoft Store and UWP apps; disabling can break Settings, Store, and pre-installed apps."},
{"WpnService / WpnUserService", "Powers toast notifications; disabling silently kills all app/email/calendar alerts."},
{"DPS / WdiServiceHost / WdiSystemHost", "Used by the built-in Windows troubleshooters and Action Center diagnostics."},
{"bthserv / BthHFSrv / BTAGService", "Breaks Bluetooth mice, keyboards, and headphones if you use any."},
{"WbioSrvc / NgcSvc", "Breaks fingerprint/face sign-in and Windows Hello PIN on many laptops."},
{"VSS / SWPRV (Volume Shadow Copy)", "Required for System Restore, File History, and most backup software."},
{"ThemesService", "Disabling reverts the entire UI to an unstyled, very jarring look."},
{"WaaSMedicSvc", "Protected by Windows; forcing it off risks breaking Windows Update."},
{"LicenseManager", "Can interfere with Store app licensing and activation status checks."},
{"FrameServer (Camera Frame Server)", "Breaks Zoom/Teams/Skype video calls and the Camera app."},
{"TabletInputService", "Disables the on-screen keyboard, needed on touchscreens/tablets."},
{"camsvc (Capability Access Manager)", "Broker for camera/mic/location permissions; disabling can block apps from using them entirely."},
{"cbdhsvc (Clipboard User Service)", "Powers clipboard history/sync; can interfere with normal copy-paste."},
{"SystemEventsBroker", "Core event broker used throughout the shell and UWP apps."},
{"DsmSvc / DeviceAssociationService", "Handles driver install and pairing when you plug in new hardware."},
{"vds (Virtual Disk)", "Needed by Disk Management for mounting VHDs and some partition operations."},
{"HidSvc", "Can control custom hotkeys/media keys on branded keyboards and mice."},
{"WpcMonSvc (Parental Controls)", "Skipped in case Family Safety restrictions are configured on this PC."},
};
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
static std::string Trim(const std::string& s) {
size_t start = s.find_first_not_of(" \t\r\n");
if (start == std::string::npos) return "";
size_t end = s.find_last_not_of(" \t\r\n");
return s.substr(start, end - start + 1);
}
static void PrintSection(const std::string& title) {
std::cout << "\n============================================================\n";
std::cout << " " << title << "\n";
std::cout << "============================================================\n";
}
static bool AskYesNo(const std::string& question, bool defaultYes = true) {
std::cout << question << (defaultYes ? " [Y/n]: " : " [y/N]: ");
std::string line;
std::getline(std::cin, line);
if (line.empty()) return defaultYes;
char c = static_cast<char>(tolower(static_cast<unsigned char>(line[0])));
return c == 'y';
}
struct CmdResult {
int exitCode = -1;
std::string output;
};
static CmdResult RunCommand(const std::string& cmd) {
CmdResult result;
std::string fullCmd = cmd + " 2>&1";
FILE* pipe = _popen(fullCmd.c_str(), "r");
if (!pipe) {
result.output = "[ERROR] Failed to launch command.";
return result;
}
char buffer[256];
while (fgets(buffer, sizeof(buffer), pipe)) {
result.output += buffer;
}
result.exitCode = _pclose(pipe);
return result;
}
// ---------------------------------------------------------------------------
// Elevation
// ---------------------------------------------------------------------------
static bool IsElevated() {
BOOL isAdmin = FALSE;
PSID adminGroup = nullptr;
SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY;
if (AllocateAndInitializeSid(&ntAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &adminGroup)) {
CheckTokenMembership(nullptr, adminGroup, &isAdmin);
FreeSid(adminGroup);
}
return isAdmin == TRUE;
}
static void RelaunchElevated() {
wchar_t path[MAX_PATH];
GetModuleFileNameW(nullptr, path, MAX_PATH);
SHELLEXECUTEINFOW sei = { sizeof(sei) };
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.lpVerb = L"runas";
sei.lpFile = path;
sei.nShow = SW_NORMAL;
if (!ShellExecuteExW(&sei)) {
std::cerr << "Elevation request was cancelled or failed. "
"Please right-click the program and choose 'Run as administrator'.\n";
}
}
// ---------------------------------------------------------------------------
// System Restore point (best effort)
// ---------------------------------------------------------------------------
static void TryCreateRestorePoint() {
HMODULE hSrClient = LoadLibraryW(L"srclient.dll");
if (!hSrClient) {
std::cout << "[INFO] System Restore module not available; skipping restore point.\n";
return;
}
auto SRSetRestorePointW_f =
reinterpret_cast<SRSetRestorePointW_t>(GetProcAddress(hSrClient, "SRSetRestorePointW"));
if (!SRSetRestorePointW_f) {
std::cout << "[INFO] SRSetRestorePointW not found; skipping restore point.\n";
FreeLibrary(hSrClient);
return;
}
RESTOREPOINTINFOW rpInfo = {};
rpInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
rpInfo.dwRestorePtType = APPLICATION_INSTALL;
wcsncpy(rpInfo.szDescription, L"Debloater - before service/task changes", DESCRIPTION_LEN - 1);
STATEMGRSTATUS smStatus = {};
BOOL ok = SRSetRestorePointW_f(&rpInfo, &smStatus);
if (ok) {
g_restoreSeq = smStatus.llSequenceNumber;
g_restorePointStarted = true;
std::cout << "[OK] System Restore point created (sequence " << g_restoreSeq << ").\n";
}
else {
std::cout << "[WARN] Could not create a System Restore point "
"(System Restore may be turned off). Proceeding without one.\n";
}
FreeLibrary(hSrClient);
}
static void FinishRestorePoint() {
if (!g_restorePointStarted) return;
HMODULE hSrClient = LoadLibraryW(L"srclient.dll");
if (!hSrClient) return;
auto SRSetRestorePointW_f =
reinterpret_cast<SRSetRestorePointW_t>(GetProcAddress(hSrClient, "SRSetRestorePointW"));
if (SRSetRestorePointW_f) {
RESTOREPOINTINFOW rpInfo = {};
rpInfo.dwEventType = END_SYSTEM_CHANGE;
rpInfo.dwRestorePtType = APPLICATION_INSTALL;
rpInfo.llSequenceNumber = g_restoreSeq;
STATEMGRSTATUS smStatus = {};
SRSetRestorePointW_f(&rpInfo, &smStatus);
}
FreeLibrary(hSrClient);
}
// ---------------------------------------------------------------------------
// Actions
// ---------------------------------------------------------------------------
static void DisableService(const SvcEntry& svc) {
std::cout << "\n[SERVICE] " << svc.display << " (" << svc.id << ")\n";
std::cout << " -> Setting startup type to Disabled...\n";
CmdResult cfg = RunCommand("sc config \"" + svc.id + "\" start= disabled");
if (cfg.exitCode == 0) {
std::cout << " [OK] Startup type set to Disabled.\n";
g_stats.servicesDisabled++;
}
else if (cfg.output.find("1060") != std::string::npos ||
cfg.output.find("does not exist") != std::string::npos) {
std::cout << " [SKIP] Service not present on this system.\n";
g_stats.servicesNotFound++;
return;
}
else {
std::cout << " [FAIL] " << Trim(cfg.output) << "\n";
g_stats.servicesFailed++;
return;
}
std::cout << " -> Stopping service if currently running...\n";
CmdResult stop = RunCommand("sc stop \"" + svc.id + "\"");
if (stop.exitCode == 0) {
std::cout << " [OK] Service stopped.\n";
}
else if (stop.output.find("1062") != std::string::npos ||
stop.output.find("has not been started") != std::string::npos) {
std::cout << " [OK] Service was already stopped.\n";
}
else {
std::cout << " [INFO] Could not stop it right now (it will stop unloading on next reboot): "
<< Trim(stop.output) << "\n";
}
}
static void DisableTask(const TaskEntry& task) {
std::cout << "\n[TASK] " << task.display << "\n";
std::cout << " -> Path: " << task.path << "\n";
CmdResult res = RunCommand("schtasks /Change /TN \"" + task.path + "\" /Disable");
if (res.exitCode == 0) {
std::cout << " [OK] Task disabled.\n";
g_stats.tasksDisabled++;
}
else if (res.output.find("cannot find") != std::string::npos ||
res.output.find("does not exist") != std::string::npos ||
res.output.find("ERROR:") != std::string::npos) {
std::cout << " [SKIP] Task not found on this system (paths can vary by Windows version/installed apps).\n";
g_stats.tasksNotFound++;
}
else {
std::cout << " [FAIL] " << Trim(res.output) << "\n";
g_stats.tasksFailed++;
}
}
// ---------------------------------------------------------------------------
// main
// ---------------------------------------------------------------------------
int main(int argc, char** argv) {
bool skipConfirm = false;
bool skipRestorePoint = false;
for (int i = 1; i < argc; ++i) {
std::string a = argv[i];
if (a == "--yes") skipConfirm = true;
if (a == "--no-restore-point") skipRestorePoint = true;
}
std::cout << "==============================================\n";
std::cout << " Windows Debloater - Safe Services & Tasks \n";
std::cout << "==============================================\n";
std::cout << "Disables a curated set of background services and scheduled\n";
std::cout << "tasks that are safe to turn off on most home PCs. Anything\n";
std::cout << "that could break Bluetooth, the Store, notifications, System\n";
std::cout << "Restore, Windows Hello, camera/mic access, or Windows Update\n";
std::cout << "is intentionally left alone (listed at the end).\n";
if (!IsElevated()) {
std::cout << "\nThis program needs to run as Administrator.\n";
std::cout << "Requesting elevation...\n";
RelaunchElevated();
return 0;
}
std::cout << "\n[OK] Running with Administrator privileges.\n";
if (!skipRestorePoint) {
if (skipConfirm || AskYesNo("\nCreate a System Restore point before making changes?")) {
std::cout << "\nCreating a System Restore point...\n";
TryCreateRestorePoint();
}
}
if (!skipConfirm) {
if (!AskYesNo("\nProceed with disabling the services and tasks listed below?")) {
std::cout << "Cancelled. No changes were made.\n";
return 0;
}
}
for (const auto& section : g_serviceSections) {
PrintSection(section.title);
for (const auto& item : section.services) {
DisableService(item);
}
}
PrintSection("Scheduled Tasks");
for (const auto& task : g_tasks) {
DisableTask(task);
}
FinishRestorePoint();
PrintSection("Skipped On Purpose (left untouched)");
for (const auto& item : g_skipped) {
std::cout << " - " << item.id << "\n " << item.reason << "\n";
}
PrintSection("Summary");
std::cout << "Services disabled : " << g_stats.servicesDisabled << "\n";
std::cout << "Services not found: " << g_stats.servicesNotFound << "\n";
std::cout << "Services failed : " << g_stats.servicesFailed << "\n";
std::cout << "Tasks disabled : " << g_stats.tasksDisabled << "\n";
std::cout << "Tasks not found : " << g_stats.tasksNotFound << "\n";
std::cout << "Tasks failed : " << g_stats.tasksFailed << "\n";
std::cout << "\nA reboot is recommended so the disabled services fully unload.\n";
std::cout << "\nPress Enter to exit...";
std::cin.get();
return 0;
}