-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdefenderSubmissionToggle.cpp
More file actions
89 lines (72 loc) · 2.95 KB
/
Copy pathdefenderSubmissionToggle.cpp
File metadata and controls
89 lines (72 loc) · 2.95 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
#include <iostream>
#include <cstdlib>
#include <Windows.h>
#include <cstdlib>
void setRegistryValue(HKEY rootKey, const std::string& subKey, const std::string& valueName, DWORD valueType, DWORD valueData) {
HKEY key;
LONG result = RegOpenKeyExA(rootKey, subKey.c_str(), 0, KEY_SET_VALUE, &key);
if (result == ERROR_SUCCESS) {
result = RegSetValueExA(key, valueName.c_str(), 0, valueType, reinterpret_cast<const BYTE*>(&valueData), sizeof(DWORD));
if (result != ERROR_SUCCESS) {
std::cerr << "Failed to set registry value: " << subKey << std::endl;
}
RegCloseKey(key);
}
else {
std::cerr << "Failed to open registry key: " << subKey << std::endl;
}
}
void deleteRegistryValue(HKEY rootKey, const std::string& subKey, const std::string& valueName) {
HKEY key;
LONG result = RegOpenKeyExA(rootKey, subKey.c_str(), 0, KEY_SET_VALUE, &key);
if (result == ERROR_SUCCESS) {
// Delete the registry value
result = RegDeleteValueA(key, valueName.c_str());
if (result != ERROR_SUCCESS) {
std::cerr << "Failed to delete registry value: " << subKey << std::endl;
}
RegCloseKey(key);
}
else {
std::cerr << "Failed to open registry key: " << subKey << std::endl;
}
}
bool controlService(const std::string& serviceName, const std::string& command) {
std::string netCommand = "net " + command + " " + serviceName;
int result = std::system(netCommand.c_str());
return result == 0;
}
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: ToggleServices.exe --enable/--disable" << std::endl;
return 1;
}
std::string option = argv[1];
if (option == "--enable") {
// Enable default settings (delete the registry value)
deleteRegistryValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Policies\\Microsoft\\Windows Defender\\Spynet", "SubmitSamplesConsent");
std::cout << "Enabled default settings." << std::endl;
// Start the NIS service
controlService("WdNisSvc", "start");
std::cout << "Started WdNisSvc service." << std::endl;
// Start the DoSvc service
controlService("dosvc", "start");
std::cout << "Started dosvc service." << std::endl;
}
else if (option == "--disable") {
// Disable sample submission
setRegistryValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Policies\\Microsoft\\Windows Defender\\Spynet", "SubmitSamplesConsent", REG_DWORD, 2);
std::cout << "Disabled sample submission." << std::endl;
// Stop the NIS service
controlService("WdNisSvc", "stop");
std::cout << "Stopped WdNisSvc service." << std::endl;
// Stop the DoSvc service
controlService("dosvc", "stop");
std::cout << "Stopped dosvc service." << std::endl;
}
else {
std::cerr << "Invalid option. Use --enable or --disable." << std::endl;
return 1;
}
return 0;
}