工程核心文件如下:
UpdateProhibited/
├── UpdateProhibited.cpp # 主程序逻辑,Win32 GUI + 系统控制逻辑
├── UpdateProhibited.ini # 行为配置,兼容 Wub.ini 的关键 section
├── UpdateProhibited.rc # 图标、版本资源
├── UpdateProhibited.manifest # requireAdministrator + Common Controls v6
├── UpdateProhibited.ico # 从 R-C.png 转换得到的程序图标
└── UpdateProhibited.vcxproj # VS C++ 工程
0x01 从原程序行为抽象到配置驱动
原始 Wub.ini 的核心结构可以归纳为几个 section:
[Main]
Language=Chinese
LastSelected=1
SetTaskScheduler=1
SetRegNoAutoUpdate=1
SetRegNoTrayIcon=1
SetImagePath=1
ProcessBlockOptions=1
ProcessCloseOptions=1
[Service_List]
; 2=Auto
; 3=Manual
; 4=Disabled
wuauserv=2,4
dosvc=2,4
WaaSMedicSvc=3,4
UsoSvc=2,3
BITS=3,3
InstallService=3,4
[TaskScheduler_List]
; 0=Without Action
; 1=Enable Task
; 2=Disable Task
Microsoft\Windows\WindowsUpdate\*=1,2
Microsoft\Windows\UpdateOrchestrator\*=1,2
[Block_Process_List]
; 0=Without Action
; 1=Unblock the Process
; 2=Block the Process
UsoClient.exe=1,2
MusNotification.exe=1,2
[Close_Process_List]
; 0=Without Action
; 1=Closes the process
MoUsoCoreWorker.exe=0,1
[Service_Check]
SU10Guard=4,3
TrustedInstaller=3,3
每一条 name=a,b 都表示“双态规则”:
- 第一个值用于
Enable Updates
- 第二个值用于
Disable Updates
例如:
wuauserv=2,4
含义是:
- 启用更新时,将
wuauserv 设置为 2=Automatic
- 禁用更新时,将
wuauserv 设置为 4=Disabled
C++ 中用一个简单结构统一承载这种规则:
struct PairRule {
std::wstring name;
int enableAction;
int disableAction;
};
默认服务规则直接写在程序里,确保没有 ini 文件时程序仍然可运行:
const std::vector<PairRule> kDefaultServiceRules = {
{L"wuauserv", 2, 4},
{L"dosvc", 2, 4},
{L"WaaSMedicSvc", 3, 4},
{L"UsoSvc", 2, 3},
{L"BITS", 3, 3},
{L"InstallService", 3, 4},
};
0x02 配置文件定位与自动生成
程序启动时会优先查找同目录的 UpdateProhibited.ini,如果不存在,会向父目录寻找原版 Wub.ini。这样既能独立运行,也能复用原项目已有配置。
核心逻辑:
std::wstring FindConfigPath(bool createIfMissing) {
if (!g_configPath.empty()) {
return g_configPath;
}
std::wstring dir = GetExeDir();
std::wstring walk = dir;
for (int i = 0; i < 5 && !walk.empty(); ++i) {
std::wstring local = JoinPath(walk, L"UpdateProhibited.ini");
if (FileExists(local)) {
g_configPath = local;
return g_configPath;
}
std::wstring wub = JoinPath(walk, L"Wub.ini");
if (FileExists(wub)) {
g_configPath = wub;
return g_configPath;
}
walk = ParentPath(walk);
}
g_configPath = JoinPath(dir, L"UpdateProhibited.ini");
if (createIfMissing) {
WriteUtf16File(g_configPath, kDefaultConfig);
}
return g_configPath;
}
写入 UTF-16 文件时显式写 BOM:
bool WriteUtf16File(const std::wstring& path, const wchar_t* text) {
HANDLE file = CreateFileW(path.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
if (file == INVALID_HANDLE_VALUE) {
return GetLastError() == ERROR_FILE_EXISTS;
}
DWORD written = 0;
const BYTE bom[] = {0xff, 0xfe};
BOOL ok = WriteFile(file, bom, sizeof(bom), &written, nullptr);
if (ok) {
DWORD bytes = static_cast<DWORD>(std::wcslen(text) * sizeof(wchar_t));
ok = WriteFile(file, text, bytes, &written, nullptr);
}
CloseHandle(file);
return ok != FALSE;
}
0x03 配置解析:用 Win32 Profile API 复用 INI 语义
项目没有手写 ini parser,而是直接使用 Windows 提供的 Profile API:
std::vector<PairRule> LoadPairSection(const wchar_t* section, const std::vector<PairRule>& defaults) {
std::wstring path = FindConfigPath(true);
std::vector<wchar_t> buffer(64 * 1024);
DWORD copied = GetPrivateProfileSectionW(section, buffer.data(), static_cast<DWORD>(buffer.size()), path.c_str());
if (copied == 0) {
return defaults;
}
std::vector<PairRule> rules;
for (wchar_t* item = buffer.data(); *item; item += std::wcslen(item) + 1) {
std::wstring line(item);
size_t eq = line.find(L'=');
if (eq == std::wstring::npos) {
continue;
}
std::wstring name = Trim(line.substr(0, eq));
std::wstring value = Trim(line.substr(eq + 1));
int first = 0;
int second = 0;
if (!name.empty() && ParsePair(value, first, second)) {
rules.push_back({name, first, second});
}
}
return rules.empty() ? defaults : rules;
}
GetPrivateProfileSectionW 返回的是多字符串块,形式类似:
key=value\0
key=value\0
\0
所以遍历方式是:
for (wchar_t* item = buffer.data(); *item; item += std::wcslen(item) + 1) {
// item points to one key=value pair
}
[Main] 的开关则用 GetPrivateProfileIntW 读取:
ConfigOptions LoadConfigOptions() {
std::wstring path = FindConfigPath(true);
ConfigOptions options;
options.setTaskScheduler = GetPrivateProfileIntW(L"Main", L"SetTaskScheduler", 1, path.c_str()) != 0;
options.setRegNoAutoUpdate = GetPrivateProfileIntW(L"Main", L"SetRegNoAutoUpdate", 1, path.c_str()) != 0;
options.setRegNoTrayIcon = GetPrivateProfileIntW(L"Main", L"SetRegNoTrayIcon", 1, path.c_str()) != 0;
options.setImagePath = GetPrivateProfileIntW(L"Main", L"SetImagePath", 1, path.c_str()) != 0;
options.processBlockOptions = GetPrivateProfileIntW(L"Main", L"ProcessBlockOptions", 1, path.c_str()) != 0;
options.processCloseOptions = GetPrivateProfileIntW(L"Main", L"ProcessCloseOptions", 1, path.c_str()) != 0;
return options;
}
这让所有关键行为都可以通过 ini 调整,而不是写死在 UI 逻辑里。
0x04 主执行流:ApplyCore 是行为编排中心
ApplyCore 是整个项目最重要的函数。UI 和命令行最终都会进入这里。
bool ApplyCore(bool enable, bool protect, std::vector<std::wstring>& log) {
bool ok = true;
ConfigOptions options = LoadConfigOptions();
std::vector<PairRule> serviceRules = LoadPairSection(L"Service_List", kDefaultServiceRules);
log.push_back(enable ? L"Mode: Enable Updates" : L"Mode: Disable Updates");
log.push_back(L"Config: " + FindConfigPath(true));
ok &= SetUpdatePolicies(enable, options, log);
if (enable && options.setImagePath) {
ok &= SetServiceImagePaths(true, serviceRules, log);
}
ok &= SetServices(enable, protect, log);
if (enable) {
if (options.setTaskScheduler) {
ok &= SetScheduledTasks(true, log);
} else {
log.push_back(L"Task Scheduler rules: skipped by config");
}
ok &= SetProcessRules(true, false, options.processBlockOptions, log);
} else if (protect) {
if (!enable && options.setImagePath) {
ok &= SetServiceImagePaths(false, serviceRules, log);
} else if (!options.setImagePath) {
log.push_back(L"Service ImagePath guard: skipped by config");
}
if (options.setTaskScheduler) {
ok &= SetScheduledTasks(enable, log);
} else {
log.push_back(L"Task Scheduler rules: skipped by config");
}
ok &= SetProcessRules(enable, options.processCloseOptions, options.processBlockOptions, log);
} else {
log.push_back(L"Extended task/process guards skipped");
}
log.push_back(ok ? L"Operation finished" : L"Operation finished with errors");
return ok;
}
这里有一个值得注意的设计:Enable Updates 会尽量撤销可逆保护项,即使用户没有勾选 Protect Services Settings。原因很简单:如果用户之前禁用时启用了保护,恢复时就应该尽力把保护解除,否则容易出现“服务启动类型恢复了,但 ImagePath 或 IFEO 仍然阻断”的半恢复状态。
执行链路可以概括为:
GUI / CLI
-> ApplyCore(enable, protect)
-> SetUpdatePolicies()
-> SetServiceImagePaths(enable) # enable 时先恢复
-> SetServices()
-> SetServiceImagePaths(false) # disable + protect 时阻断
-> SetScheduledTasks()
-> SetProcessRules()
0x05 服务控制:SCM + ChangeServiceConfig
Windows 服务控制使用 Service Control Manager,也就是 OpenSCManagerW + OpenServiceW + ChangeServiceConfigW。
启动类型映射如下:
DWORD StartTypeFromNumber(int value) {
switch (value) {
case 2:
return SERVICE_AUTO_START;
case 3:
return SERVICE_DEMAND_START;
case 4:
return SERVICE_DISABLED;
default:
return SERVICE_NO_CHANGE;
}
}
服务状态读取使用 QueryServiceConfigW 和 QueryServiceStatusEx:
ServiceSnapshot QueryServiceSnapshot(SC_HANDLE scm, const std::wstring& name) {
ServiceSnapshot snapshot;
SC_HANDLE service = OpenServiceW(scm, name.c_str(), SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS);
if (!service) {
snapshot.error = GetLastError();
return snapshot;
}
snapshot.exists = true;
DWORD needed = 0;
QueryServiceConfigW(service, nullptr, 0, &needed);
if (needed) {
std::unique_ptr<BYTE[]> bytes(new BYTE[needed]);
auto config = reinterpret_cast<QUERY_SERVICE_CONFIGW*>(bytes.get());
if (QueryServiceConfigW(service, config, needed, &needed)) {
snapshot.startType = config->dwStartType;
} else {
snapshot.error = GetLastError();
}
}
SERVICE_STATUS_PROCESS status{};
DWORD statusNeeded = 0;
if (QueryServiceStatusEx(service, SC_STATUS_PROCESS_INFO, reinterpret_cast<LPBYTE>(&status), sizeof(status), &statusNeeded)) {
snapshot.currentState = status.dwCurrentState;
} else if (!snapshot.error) {
snapshot.error = GetLastError();
}
CloseServiceHandle(service);
return snapshot;
}
真正修改服务时,禁用分支会先尝试停止服务,再改启动类型:
if (!enable) {
StopServiceIfRunning(service, rule.name, log);
}
if (ChangeServiceConfigW(service, SERVICE_NO_CHANGE, targetStart, SERVICE_NO_CHANGE,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) {
log.push_back(rule.name + L": start type -> " + StartTypeText(targetStart));
} else {
log.push_back(rule.name + L": start type failed (" + FormatError(GetLastError()) + L")");
ok = false;
}
完整服务处理函数:
bool SetServices(bool enable, bool protect, std::vector<std::wstring>& log) {
bool ok = true;
std::vector<PairRule> rules = LoadPairSection(L"Service_List", kDefaultServiceRules);
SC_HANDLE scm = OpenSCManagerW(nullptr, nullptr, SC_MANAGER_CONNECT);
if (!scm) {
log.push_back(L"OpenSCManagerW failed: " + FormatError(GetLastError()));
return false;
}
for (const PairRule& rule : rules) {
DWORD targetStart = StartTypeFromNumber(enable ? rule.enableAction : rule.disableAction);
if (targetStart == SERVICE_NO_CHANGE) {
log.push_back(rule.name + L": skipped");
continue;
}
DWORD access = SERVICE_CHANGE_CONFIG | SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS | SERVICE_START | SERVICE_STOP;
SC_HANDLE service = OpenServiceW(scm, rule.name.c_str(), access);
if (!service) {
DWORD err = GetLastError();
log.push_back(rule.name + L": unavailable (" + FormatError(err) + L")");
if (err != ERROR_SERVICE_DOES_NOT_EXIST) {
ok = false;
}
continue;
}
if (!enable) {
StopServiceIfRunning(service, rule.name, log);
}
if (ChangeServiceConfigW(service, SERVICE_NO_CHANGE, targetStart, SERVICE_NO_CHANGE,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) {
log.push_back(rule.name + L": start type -> " + StartTypeText(targetStart));
} else {
log.push_back(rule.name + L": start type failed (" + FormatError(GetLastError()) + L")");
ok = false;
}
if (enable && targetStart == SERVICE_AUTO_START) {
StartServiceIfNeeded(service, rule.name, log);
}
if (!enable && protect) {
ClearFailureActions(service, rule.name, log);
}
CloseServiceHandle(service);
}
CloseServiceHandle(scm);
return ok;
}
ClearFailureActions 用于清掉服务恢复策略,降低系统自动拉起服务的概率:
void ClearFailureActions(SC_HANDLE service, const std::wstring& name, std::vector<std::wstring>& log) {
SERVICE_FAILURE_ACTIONSW actions{};
actions.dwResetPeriod = INFINITE;
if (ChangeServiceConfig2W(service, SERVICE_CONFIG_FAILURE_ACTIONS, &actions)) {
log.push_back(name + L": recovery actions cleared");
}
}
0x06 注册表策略:NoAutoUpdate 与 Windows Update UX
注册表策略对应 [Main] 中两个开关:
SetRegNoAutoUpdate=1
SetRegNoTrayIcon=1
实现中映射为:
NoAutoUpdate
SetDisableUXWUAccess
代码如下:
bool SetUpdatePolicies(bool enable, const ConfigOptions& options, std::vector<std::wstring>& log) {
const std::wstring windowsUpdate = L"SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate";
const std::wstring au = windowsUpdate + L"\\AU";
bool ok = true;
if (options.setRegNoAutoUpdate) {
bool itemOk = enable ? DeleteValue(HKEY_LOCAL_MACHINE, au, L"NoAutoUpdate")
: SetDwordValue(HKEY_LOCAL_MACHINE, au, L"NoAutoUpdate", 1);
ok &= itemOk;
log.push_back(itemOk ? L"NoAutoUpdate policy: updated" : L"NoAutoUpdate policy: failed");
}
if (options.setRegNoTrayIcon) {
bool itemOk = enable ? DeleteValue(HKEY_LOCAL_MACHINE, windowsUpdate, L"SetDisableUXWUAccess")
: SetDwordValue(HKEY_LOCAL_MACHINE, windowsUpdate, L"SetDisableUXWUAccess", 1);
ok &= itemOk;
log.push_back(itemOk ? L"Windows Update UX policy: updated" : L"Windows Update UX policy: failed");
}
if (!options.setRegNoAutoUpdate && !options.setRegNoTrayIcon) {
log.push_back(L"Registry policies: skipped by config");
}
return ok;
}
底层写入使用 RegCreateKeyExW + RegSetValueExW:
bool SetDwordValue(HKEY root, const std::wstring& subkey, const std::wstring& name, DWORD value) {
HKEY key = nullptr;
LSTATUS status = RegCreateKeyExW(root, subkey.c_str(), 0, nullptr, REG_OPTION_NON_VOLATILE,
KEY_SET_VALUE | KEY_WOW64_64KEY, nullptr, &key, nullptr);
if (status != ERROR_SUCCESS) {
return false;
}
status = RegSetValueExW(key, name.c_str(), 0, REG_DWORD, reinterpret_cast<const BYTE*>(&value), sizeof(value));
RegCloseKey(key);
return status == ERROR_SUCCESS;
}
删除值则使用:
bool DeleteValue(HKEY root, const std::wstring& subkey, const std::wstring& name) {
HKEY key = nullptr;
LSTATUS status = RegOpenKeyExW(root, subkey.c_str(), 0, KEY_SET_VALUE | KEY_WOW64_64KEY, &key);
if (status != ERROR_SUCCESS) {
return status == ERROR_FILE_NOT_FOUND;
}
status = RegDeleteValueW(key, name.c_str());
RegCloseKey(key);
return status == ERROR_SUCCESS || status == ERROR_FILE_NOT_FOUND;
}
0x07 ImagePath 保护:备份、阻断、恢复
SetImagePath=1 是一个更强的服务保护策略:禁用时把服务的 ImagePath 替换成无害退出命令,启用时从备份恢复。
项目使用两个备份值:
constexpr wchar_t kBackupImagePath[] = L"UpdateProhibited_OriginalImagePath";
constexpr wchar_t kBackupImagePathType[] = L"UpdateProhibited_OriginalImagePathType";
禁用时使用的阻断路径:
const std::wstring blocker = L"%SystemRoot%\\System32\\cmd.exe /c exit";
读取字符串型注册表值:
bool QueryStringValue(HKEY root, const std::wstring& subkey, const std::wstring& name, std::wstring& value, DWORD& type) {
HKEY key = nullptr;
LSTATUS status = RegOpenKeyExW(root, subkey.c_str(), 0, KEY_QUERY_VALUE | KEY_WOW64_64KEY, &key);
if (status != ERROR_SUCCESS) {
return false;
}
DWORD size = 0;
status = RegQueryValueExW(key, name.c_str(), nullptr, &type, nullptr, &size);
if (status != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
RegCloseKey(key);
return false;
}
std::vector<wchar_t> buffer((size / sizeof(wchar_t)) + 2);
status = RegQueryValueExW(key, name.c_str(), nullptr, &type, reinterpret_cast<BYTE*>(buffer.data()), &size);
RegCloseKey(key);
if (status != ERROR_SUCCESS) {
return false;
}
value.assign(buffer.data());
return true;
}
写字符串值:
bool SetStringValue(HKEY root, const std::wstring& subkey, const std::wstring& name, const std::wstring& value, DWORD type) {
HKEY key = nullptr;
LSTATUS status = RegCreateKeyExW(root, subkey.c_str(), 0, nullptr, REG_OPTION_NON_VOLATILE,
KEY_SET_VALUE | KEY_WOW64_64KEY, nullptr, &key, nullptr);
if (status != ERROR_SUCCESS) {
return false;
}
DWORD bytes = static_cast<DWORD>((value.size() + 1) * sizeof(wchar_t));
status = RegSetValueExW(key, name.c_str(), 0, type, reinterpret_cast<const BYTE*>(value.c_str()), bytes);
RegCloseKey(key);
return status == ERROR_SUCCESS;
}
完整 ImagePath 保护逻辑:
bool SetServiceImagePaths(bool enable, const std::vector<PairRule>& serviceRules, std::vector<std::wstring>& log) {
constexpr wchar_t kBackupImagePath[] = L"UpdateProhibited_OriginalImagePath";
constexpr wchar_t kBackupImagePathType[] = L"UpdateProhibited_OriginalImagePathType";
const std::wstring blocker = L"%SystemRoot%\\System32\\cmd.exe /c exit";
bool ok = true;
for (const PairRule& rule : serviceRules) {
if (rule.disableAction != 4) {
continue;
}
std::wstring subkey = L"SYSTEM\\CurrentControlSet\\Services\\" + rule.name;
if (enable) {
std::wstring original;
DWORD originalType = REG_EXPAND_SZ;
DWORD savedType = REG_EXPAND_SZ;
if (!QueryStringValue(HKEY_LOCAL_MACHINE, subkey, kBackupImagePath, original, originalType)) {
log.push_back(rule.name + L": ImagePath restore skipped");
continue;
}
DWORD typeValue = REG_EXPAND_SZ;
if (QueryDwordValue(HKEY_LOCAL_MACHINE, subkey, kBackupImagePathType, savedType)) {
typeValue = savedType;
}
bool itemOk = SetStringValue(HKEY_LOCAL_MACHINE, subkey, L"ImagePath", original, typeValue);
itemOk &= DeleteValue(HKEY_LOCAL_MACHINE, subkey, kBackupImagePath);
itemOk &= DeleteValue(HKEY_LOCAL_MACHINE, subkey, kBackupImagePathType);
ok &= itemOk;
log.push_back(rule.name + (itemOk ? L": ImagePath restored" : L": ImagePath restore failed"));
} else {
std::wstring current;
DWORD currentType = REG_EXPAND_SZ;
if (!QueryStringValue(HKEY_LOCAL_MACHINE, subkey, L"ImagePath", current, currentType)) {
log.push_back(rule.name + L": ImagePath unavailable");
ok = false;
continue;
}
std::wstring existingBackup;
DWORD existingBackupType = REG_EXPAND_SZ;
bool hasBackup = QueryStringValue(HKEY_LOCAL_MACHINE, subkey, kBackupImagePath, existingBackup, existingBackupType);
bool itemOk = true;
if (!hasBackup && ToLower(current) != ToLower(blocker)) {
itemOk &= SetStringValue(HKEY_LOCAL_MACHINE, subkey, kBackupImagePath, current, currentType);
itemOk &= SetDwordValue(HKEY_LOCAL_MACHINE, subkey, kBackupImagePathType, currentType);
}
itemOk &= SetStringValue(HKEY_LOCAL_MACHINE, subkey, L"ImagePath", blocker, REG_EXPAND_SZ);
ok &= itemOk;
log.push_back(rule.name + (itemOk ? L": ImagePath blocked" : L": ImagePath block failed"));
}
}
return ok;
}
这个模块的重点是可逆性:第一次禁用时保存原始 ImagePath,恢复时写回原值,并删除备份键。
Windows Update 不只依赖服务,还依赖一组计划任务,例如:
Microsoft\Windows\WindowsUpdate\*=1,2
Microsoft\Windows\UpdateOrchestrator\*=1,2
Microsoft\Windows\WaaSMedic\PerformRemediation=1,2
项目使用 Task Scheduler COM 接口:
bool ConnectTaskService(ITaskService** outService, std::vector<std::wstring>& log) {
*outService = nullptr;
HRESULT hr = CoCreateInstance(CLSID_TaskScheduler, nullptr, CLSCTX_INPROC_SERVER,
IID_ITaskService, reinterpret_cast<void**>(outService));
if (FAILED(hr)) {
log.push_back(L"Task Scheduler: CoCreateInstance failed (0x" + std::to_wstring(static_cast<unsigned long>(hr)) + L")");
return false;
}
hr = (*outService)->Connect(_variant_t(), _variant_t(), _variant_t(), _variant_t());
if (FAILED(hr)) {
log.push_back(L"Task Scheduler: Connect failed (0x" + std::to_wstring(static_cast<unsigned long>(hr)) + L")");
(*outService)->Release();
*outService = nullptr;
return false;
}
return true;
}
任务路径先拆分为 folder + task name:
bool SplitTaskPath(const std::wstring& fullPath, std::wstring& folderPath, std::wstring& taskName) {
std::wstring normalized = NormalizeTaskPath(fullPath);
size_t pos = normalized.find_last_of(L'\\');
if (pos == std::wstring::npos) {
folderPath = L"\\";
taskName = normalized;
return !taskName.empty();
}
folderPath = L"\\" + normalized.substr(0, pos);
taskName = normalized.substr(pos + 1);
return !taskName.empty();
}
如果任务名是 *,就枚举整个文件夹:
if (taskName == L"*") {
IRegisteredTaskCollection* tasks = nullptr;
hr = folder->GetTasks(TASK_ENUM_HIDDEN, &tasks);
if (FAILED(hr)) {
log.push_back(rule.name + L": task enumeration failed");
ok = false;
} else {
LONG count = 0;
tasks->get_Count(&count);
for (LONG i = 1; i <= count; ++i) {
IRegisteredTask* task = nullptr;
hr = tasks->get_Item(_variant_t(i), &task);
if (FAILED(hr) || !task) {
ok = false;
continue;
}
BSTR name = nullptr;
task->get_Name(&name);
hr = task->put_Enabled(taskEnabled ? VARIANT_TRUE : VARIANT_FALSE);
std::wstring display = name ? std::wstring(name, SysStringLen(name)) : L"(unnamed)";
if (name) {
SysFreeString(name);
}
log.push_back(display + (SUCCEEDED(hr) ? (taskEnabled ? L": task enabled" : L": task disabled")
: L": task update failed"));
if (FAILED(hr)) {
ok = false;
}
task->Release();
}
tasks->Release();
}
}
如果是具体任务名,则直接调用 GetTask:
IRegisteredTask* task = nullptr;
hr = folder->GetTask(_bstr_t(taskName.c_str()), &task);
if (FAILED(hr) || !task) {
log.push_back(rule.name + L": task unavailable");
ok = false;
} else {
hr = task->put_Enabled(taskEnabled ? VARIANT_TRUE : VARIANT_FALSE);
log.push_back(rule.name + (SUCCEEDED(hr) ? (taskEnabled ? L": task enabled" : L": task disabled")
: L": task update failed"));
ok = SUCCEEDED(hr);
task->Release();
}
统一入口:
bool SetScheduledTasks(bool enable, std::vector<std::wstring>& log) {
bool ok = true;
std::vector<PairRule> rules = LoadPairSection(L"TaskScheduler_List", kDefaultTaskRules);
HRESULT init = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
bool uninit = SUCCEEDED(init);
CoInitializeSecurity(nullptr, -1, nullptr, nullptr, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, 0, nullptr);
ITaskService* service = nullptr;
if (!ConnectTaskService(&service, log)) {
if (uninit) {
CoUninitialize();
}
return false;
}
for (const PairRule& rule : rules) {
int action = enable ? rule.enableAction : rule.disableAction;
if (action == 0) {
log.push_back(rule.name + L": task skipped");
continue;
}
if (action == 1 || action == 2) {
ok &= SetTaskRule(service, rule, action == 1, log);
}
}
service->Release();
if (uninit) {
CoUninitialize();
}
return ok;
}
0x09 进程阻断:IFEO Debugger 技术
[Block_Process_List] 的实现没有去 hook 或注入进程,而是使用 Windows 自带的 Image File Execution Options:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<process.exe>
Debugger = "%SystemRoot%\System32\cmd.exe" /c exit
当目标进程被启动时,Windows 会先启动 Debugger 指定的程序,从而达到阻断目标程序启动的效果。
生成阻断命令:
std::wstring GetCmdExitDebugger() {
wchar_t windowsDir[MAX_PATH]{};
if (!GetWindowsDirectoryW(windowsDir, MAX_PATH)) {
return L"cmd.exe /c exit";
}
return L"\"" + std::wstring(windowsDir) + L"\\System32\\cmd.exe\" /c exit";
}
写入或删除 IFEO:
bool SetIfeoDebugger(const std::wstring& processName, bool blocked, std::vector<std::wstring>& log) {
std::wstring subkey = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\" + processName;
if (!blocked) {
bool ok = DeleteValue(HKEY_LOCAL_MACHINE, subkey, L"Debugger");
log.push_back(processName + (ok ? L": process unblocked" : L": unblock failed"));
return ok;
}
HKEY key = nullptr;
LSTATUS status = RegCreateKeyExW(HKEY_LOCAL_MACHINE, subkey.c_str(), 0, nullptr, REG_OPTION_NON_VOLATILE,
KEY_SET_VALUE | KEY_WOW64_64KEY, nullptr, &key, nullptr);
if (status != ERROR_SUCCESS) {
log.push_back(processName + L": block failed (" + FormatError(status) + L")");
return false;
}
std::wstring debugger = GetCmdExitDebugger();
DWORD bytes = static_cast<DWORD>((debugger.size() + 1) * sizeof(wchar_t));
status = RegSetValueExW(key, L"Debugger", 0, REG_SZ, reinterpret_cast<const BYTE*>(debugger.c_str()), bytes);
RegCloseKey(key);
log.push_back(processName + (status == ERROR_SUCCESS ? L": process blocked" : L": block failed"));
return status == ERROR_SUCCESS;
}
[Close_Process_List] 则用于禁用时立即终止已经运行的相关进程。这里使用 Toolhelp 快照:
int TerminateMatchingProcesses(const std::wstring& processName, std::vector<std::wstring>& log) {
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE) {
log.push_back(processName + L": process snapshot failed");
return 0;
}
int closed = 0;
std::wstring target = ToLower(processName);
PROCESSENTRY32W entry{};
entry.dwSize = sizeof(entry);
if (Process32FirstW(snapshot, &entry)) {
do {
if (ToLower(entry.szExeFile) == target) {
HANDLE process = OpenProcess(PROCESS_TERMINATE, FALSE, entry.th32ProcessID);
if (process) {
if (TerminateProcess(process, 0)) {
++closed;
}
CloseHandle(process);
}
}
} while (Process32NextW(snapshot, &entry));
}
CloseHandle(snapshot);
if (closed > 0) {
log.push_back(processName + L": closed " + std::to_wstring(closed) + L" process(es)");
}
return closed;
}
规则调度:
bool SetProcessRules(bool enable, bool closeEnabled, bool blockEnabled, std::vector<std::wstring>& log) {
bool ok = true;
std::vector<PairRule> blockRules = LoadPairSection(L"Block_Process_List", kDefaultBlockProcessRules);
std::vector<PairRule> closeRules = LoadPairSection(L"Close_Process_List", kDefaultCloseProcessRules);
if (!enable && closeEnabled) {
for (const PairRule& rule : closeRules) {
int action = rule.disableAction;
if (action == 1) {
TerminateMatchingProcesses(rule.name, log);
}
}
} else if (!closeEnabled) {
log.push_back(L"Close process rules: skipped by config");
}
if (blockEnabled) {
for (const PairRule& rule : blockRules) {
int action = enable ? rule.enableAction : rule.disableAction;
if (action == 1) {
ok &= SetIfeoDebugger(rule.name, false, log);
} else if (action == 2) {
ok &= SetIfeoDebugger(rule.name, true, log);
} else {
log.push_back(rule.name + L": process rule skipped");
}
}
} else {
log.push_back(L"Block process rules: skipped by config");
}
return ok;
}
0x0A 状态判断:不要只看一个服务
状态栏显示不是硬编码某个服务,而是遍历 [Service_List] 中所有存在的服务,并综合启动类型和运行状态。
std::wstring SummarizeStatus() {
std::vector<PairRule> services = LoadPairSection(L"Service_List", kDefaultServiceRules);
SC_HANDLE scm = OpenSCManagerW(nullptr, nullptr, SC_MANAGER_CONNECT);
if (!scm) {
return Ui().serviceInfoUnavailable;
}
int existing = 0;
bool allEnabledStart = true;
bool allDisabledStart = true;
bool anyRunning = false;
for (const PairRule& rule : services) {
ServiceSnapshot snapshot = QueryServiceSnapshot(scm, rule.name);
if (!snapshot.exists) {
continue;
}
++existing;
anyRunning |= snapshot.currentState == SERVICE_RUNNING;
allEnabledStart &= snapshot.startType == StartTypeFromNumber(rule.enableAction);
allDisabledStart &= snapshot.startType == StartTypeFromNumber(rule.disableAction);
}
CloseServiceHandle(scm);
if (existing == 0) {
return Ui().serviceInfoUnavailable;
}
if (allDisabledStart && IsNoAutoUpdateSet()) {
return Ui().serviceDisabledProtected;
}
if (allDisabledStart) {
return Ui().serviceDisabled;
}
if (allEnabledStart && anyRunning) {
return Ui().serviceEnabledRunning;
}
if (allEnabledStart) {
return Ui().serviceEnabledNotRunning;
}
return Ui().serviceInfoIncorrect;
}
这也是为什么某些系统上会看到 “Service info is incorrect”:不同 Windows 版本里 UsoSvc、WaaSMedicSvc、InstallService 的默认启动类型和运行状态并不完全一致,只要和配置期望不完全匹配,就会落到这个状态。
0x0B GUI 设计:Win32 原生窗口与最小状态栏
项目使用原生 Win32 控件,没有引入 MFC/Qt/WinUI。主窗口创建入口:
HWND hwnd = CreateWindowExW(0, className, Ui().title, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 560, 210,
nullptr, nullptr, instance, nullptr);
控件创建封装为 CreateChild:
HWND CreateChild(HWND parent, const wchar_t* cls, const wchar_t* text, DWORD style, int id) {
HWND hwnd = CreateWindowExW(0, cls, text, style | WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, parent, reinterpret_cast<HMENU>(static_cast<INT_PTR>(id)),
GetModuleHandleW(nullptr), nullptr);
ApplyFont(hwnd);
return hwnd;
}
控件初始化:
void CreateControls(HWND hwnd) {
HDC dc = GetDC(hwnd);
int fontHeight = -MulDiv(9, GetDeviceCaps(dc, LOGPIXELSY), 72);
ReleaseDC(hwnd, dc);
g_font = CreateFontW(fontHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, L"Segoe UI");
const UiText& ui = Ui();
g_group = CreateChild(hwnd, L"BUTTON", ui.group, BS_GROUPBOX, IDC_GROUP);
g_enable = CreateChild(hwnd, L"BUTTON", ui.enable, BS_AUTORADIOBUTTON | WS_GROUP, IDC_ENABLE);
g_disable = CreateChild(hwnd, L"BUTTON", ui.disable, BS_AUTORADIOBUTTON, IDC_DISABLE);
g_protect = CreateChild(hwnd, L"BUTTON", ui.protect, BS_AUTOCHECKBOX, IDC_PROTECT);
g_apply = CreateChild(hwnd, L"BUTTON", ui.apply, BS_PUSHBUTTON, IDC_APPLY);
g_refresh = CreateChild(hwnd, L"BUTTON", ui.refresh, BS_PUSHBUTTON, IDC_REFRESH);
g_services = CreateChild(hwnd, L"BUTTON", ui.services, BS_PUSHBUTTON, IDC_SERVICES);
g_language = CreateChild(hwnd, L"BUTTON", LanguageButtonText(), BS_PUSHBUTTON, IDC_LANGUAGE);
g_status = CreateChild(hwnd, L"STATIC", L"", SS_LEFTNOWORDWRAP, IDC_STATUS);
SendMessageW(g_disable, BM_SETCHECK, BST_CHECKED, 0);
SendMessageW(g_protect, BM_SETCHECK, BST_CHECKED, 0);
}
布局代码:
void LayoutControls(HWND hwnd) {
RECT rc{};
GetClientRect(hwnd, &rc);
int width = rc.right - rc.left;
int margin = 14;
int groupHeight = 104;
int buttonY = 84;
int buttonW = 104;
MoveWindow(g_group, margin, margin, width - margin * 2, groupHeight, TRUE);
MoveWindow(g_enable, margin + 18, margin + 30, 160, 24, TRUE);
MoveWindow(g_disable, margin + 18, margin + 58, 160, 24, TRUE);
MoveWindow(g_protect, margin + 196, margin + 30, 210, 24, TRUE);
MoveWindow(g_apply, width - margin - buttonW, margin + 28, buttonW, 30, TRUE);
MoveWindow(g_refresh, width - margin - buttonW * 3 - 16, buttonY, buttonW, 30, TRUE);
MoveWindow(g_services, width - margin - buttonW * 2 - 8, buttonY, buttonW, 30, TRUE);
MoveWindow(g_language, width - margin - buttonW, buttonY, buttonW, 30, TRUE);
MoveWindow(g_status, margin, margin + groupHeight + 12, width - margin * 2, 24, TRUE);
}
这里特意删除了日志列表控件。详细日志仍保留在内部 std::vector<std::wstring> log 中,供命令行或调试使用,但 GUI 只展示最终状态,避免界面臃肿。
0x0C 中英 UI 实时切换
项目新增了一个语言按钮:
- 英文界面显示
中文
- 中文界面显示
English
- 点击后立即更新窗口标题、按钮、菜单、状态文字
- 当前语言写回
UpdateProhibited.ini
语言文本集中在 UiText 结构:
struct UiText {
const wchar_t* title;
const wchar_t* group;
const wchar_t* enable;
const wchar_t* disable;
const wchar_t* protect;
const wchar_t* apply;
const wchar_t* refresh;
const wchar_t* services;
const wchar_t* updateOptions;
const wchar_t* windowsServices;
const wchar_t* taskScheduler;
const wchar_t* updateTroubleshooter;
const wchar_t* commandLineInfo;
const wchar_t* about;
const wchar_t* adminRequired;
const wchar_t* pleaseWait;
const wchar_t* restartAdmin;
const wchar_t* operationFinishedErrors;
const wchar_t* serviceInfoUnavailable;
const wchar_t* serviceDisabledProtected;
const wchar_t* serviceDisabled;
const wchar_t* serviceEnabledRunning;
const wchar_t* serviceEnabledNotRunning;
const wchar_t* serviceInfoIncorrect;
const wchar_t* aboutBody;
};
运行时通过全局布尔值选择语言:
bool g_useChinese = false;
const UiText& Ui() {
static const UiText en = {
L"UpdateProhibited",
L"Windows Updates Option",
L"Enable Updates",
L"Disable Updates",
L"Protect Services Settings",
L"Apply Now",
L"Refresh",
L"Services",
L"Update Options",
L"Windows Services",
L"Task Scheduler",
L"Update Troubleshooter",
L"Command Line Info",
L"About",
L"Administrator rights required",
L"Please wait ...",
L"Restart as administrator?",
L"Operation finished with errors",
L"Service information unavailable",
L"Service is disabled and protected",
L"Service is disabled",
L"Service is enabled and running",
L"Service is enabled and not running",
L"Service info is incorrect",
L"UpdateProhibited 1.0\nNative C++ Windows Update control utility.",
};
static const UiText zh = {
L"UpdateProhibited",
L"Windows \u66F4\u65B0\u9009\u9879",
L"\u542F\u7528\u66F4\u65B0",
L"\u7981\u7528\u66F4\u65B0",
L"\u4FDD\u62A4\u670D\u52A1\u8BBE\u7F6E",
L"\u7ACB\u5373\u5E94\u7528",
L"\u5237\u65B0",
L"\u670D\u52A1",
L"\u66F4\u65B0\u9009\u9879",
L"Windows \u670D\u52A1",
L"\u4EFB\u52A1\u8BA1\u5212\u7A0B\u5E8F",
L"\u66F4\u65B0\u7591\u96BE\u89E3\u7B54",
L"\u547D\u4EE4\u884C\u4FE1\u606F",
L"\u5173\u4E8E",
L"\u9700\u8981\u7BA1\u7406\u5458\u6743\u9650",
L"\u8BF7\u7A0D\u5019 ...",
L"\u4EE5\u7BA1\u7406\u5458\u8EAB\u4EFD\u91CD\u542F\uFF1F",
L"\u64CD\u4F5C\u5B8C\u6210\u4F46\u5B58\u5728\u9519\u8BEF",
L"\u670D\u52A1\u4FE1\u606F\u4E0D\u53EF\u7528",
L"\u670D\u52A1\u5DF2\u7981\u7528\u5E76\u53D7\u4FDD\u62A4",
L"\u670D\u52A1\u5DF2\u7981\u7528",
L"\u670D\u52A1\u5DF2\u542F\u7528\u5E76\u6B63\u5728\u8FD0\u884C",
L"\u670D\u52A1\u5DF2\u542F\u7528\u4F46\u672A\u8FD0\u884C",
L"\u670D\u52A1\u4FE1\u606F\u4E0D\u6B63\u786E",
L"UpdateProhibited 1.0\n\u539F\u751F C++ Windows \u66F4\u65B0\u63A7\u5236\u5DE5\u5177\u3002",
};
return g_useChinese ? zh : en;
}
注意:中文字符串使用 \uXXXX 形式写入源码,避免源文件编码和编译器代码页不一致导致乱码。
启动时读取语言:
void LoadUiLanguage() {
std::wstring path = FindConfigPath(true);
wchar_t value[64]{};
GetPrivateProfileStringW(L"Main", L"Language", L"Auto", value,
static_cast<DWORD>(sizeof(value) / sizeof(value[0])), path.c_str());
std::wstring language = ToLower(Trim(value));
if (language == L"chinese" || language == L"zh" || language == L"zh-cn") {
g_useChinese = true;
} else if (language == L"english" || language == L"en" || language == L"en-us") {
g_useChinese = false;
} else {
g_useChinese = SystemPrefersChinese();
}
}
点击按钮后保存语言:
void SaveUiLanguage() {
WritePrivateProfileStringW(L"Main", L"Language", g_useChinese ? L"Chinese" : L"English",
FindConfigPath(true).c_str());
}
实时刷新 UI:
void ApplyUiLanguage(HWND hwnd) {
const UiText& ui = Ui();
SetWindowTextW(hwnd, ui.title);
SetWindowTextW(g_group, ui.group);
SetWindowTextW(g_enable, ui.enable);
SetWindowTextW(g_disable, ui.disable);
SetWindowTextW(g_protect, ui.protect);
SetWindowTextW(g_apply, ui.apply);
SetWindowTextW(g_refresh, ui.refresh);
SetWindowTextW(g_services, ui.services);
SetWindowTextW(g_language, LanguageButtonText());
CreateMainMenu(hwnd);
if (g_applyInProgress) {
SetStatusText(ui.pleaseWait);
} else if (!IsRunningAsAdmin()) {
SetStatusText(ui.adminRequired);
} else {
RefreshUi();
}
}
按钮事件:
case IDC_LANGUAGE:
g_useChinese = !g_useChinese;
SaveUiLanguage();
ApplyUiLanguage(hwnd);
return 0;
0x0D 消息循环与异步执行
Windows GUI 的入口是 wWinMain:
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int showCmd) {
FindConfigPath(true);
LoadUiLanguage();
std::vector<std::wstring> args = GetArgs();
int commandResult = HandleCommandLine(args);
if (commandResult >= 0) {
return commandResult;
}
INITCOMMONCONTROLSEX icc{};
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&icc);
const wchar_t* className = L"UpdateProhibitedWindow";
HICON icon = static_cast<HICON>(LoadImageW(instance, MAKEINTRESOURCEW(IDI_APP), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));
HICON smallIcon = static_cast<HICON>(LoadImageW(instance, MAKEINTRESOURCEW(IDI_APP), IMAGE_ICON, 16, 16, 0));
WNDCLASSEXW wc{};
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = WndProc;
wc.hInstance = instance;
wc.hIcon = icon;
wc.hIconSm = smallIcon;
wc.hCursor = LoadCursorW(nullptr, IDC_ARROW);
wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1);
wc.lpszClassName = className;
if (!RegisterClassExW(&wc)) {
return 1;
}
HWND hwnd = CreateWindowExW(0, className, Ui().title, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 560, 210,
nullptr, nullptr, instance, nullptr);
if (!hwnd) {
return 1;
}
ShowWindow(hwnd, showCmd);
UpdateWindow(hwnd);
MSG msg{};
while (GetMessageW(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return static_cast<int>(msg.wParam);
}
点击 “Apply Now” 后,操作在后台线程执行,避免 UI 卡死:
void BeginApply() {
if (g_applyInProgress) {
return;
}
bool enable = SendMessageW(g_enable, BM_GETCHECK, 0, 0) == BST_CHECKED;
bool protect = SendMessageW(g_protect, BM_GETCHECK, 0, 0) == BST_CHECKED;
g_applyInProgress = true;
SetControlsEnabled(false);
SetStatusText(Ui().pleaseWait);
HWND hwnd = g_hwnd;
std::thread([hwnd, enable, protect]() {
std::vector<std::wstring> log;
bool ok = ApplyCore(enable, protect, log);
PostMessageW(hwnd, WM_APPLY_DONE, ok ? 1 : 0, 0);
}).detach();
}
后台线程完成后通过 PostMessageW 回到 UI 线程:
case WM_APPLY_DONE: {
g_applyInProgress = false;
SetControlsEnabled(true);
SetStatusText(wParam ? SummarizeStatus() : Ui().operationFinishedErrors);
return 0;
}
这种模式避免了直接在工作线程里调用 UI 控件 API,也让主线程保持消息响应。
0x0E 命令行模式
除了 GUI,程序还支持命令行:
UpdateProhibited.exe /disable [/quiet] [/noprotection]
UpdateProhibited.exe /enable [/quiet] [/noprotection]
UpdateProhibited.exe /status
参数解析:
bool HasArg(const std::vector<std::wstring>& args, const wchar_t* name) {
std::wstring wanted = ToLower(name);
for (const std::wstring& arg : args) {
if (ToLower(arg) == wanted) {
return true;
}
}
return false;
}
std::vector<std::wstring> GetArgs() {
int argc = 0;
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
std::vector<std::wstring> args;
if (argv) {
for (int i = 1; i < argc; ++i) {
args.emplace_back(argv[i]);
}
LocalFree(argv);
}
return args;
}
命令行入口:
int HandleCommandLine(const std::vector<std::wstring>& args) {
if (args.empty()) {
return -1;
}
bool quiet = HasArg(args, L"/quiet") || HasArg(args, L"-quiet");
bool noProtection = HasArg(args, L"/noprotection") || HasArg(args, L"-noprotection");
bool status = HasArg(args, L"/status") || HasArg(args, L"-status");
bool help = HasArg(args, L"/?") || HasArg(args, L"/help") || HasArg(args, L"-help");
bool enable = HasArg(args, L"/enable") || HasArg(args, L"-enable");
bool disable = HasArg(args, L"/disable") || HasArg(args, L"-disable");
if (help) {
ShowCommandLineInfo(nullptr);
return 0;
}
if (status) {
std::wstringstream stream;
stream << SummarizeStatus() << L"\n\n";
for (const std::wstring& line : CollectStatusLines()) {
stream << line << L"\n";
}
if (!quiet) {
MessageBoxW(nullptr, stream.str().c_str(), Ui().title, MB_OK | MB_ICONINFORMATION);
}
return 0;
}
if (enable == disable) {
return -1;
}
if (!IsRunningAsAdmin()) {
if (!quiet) {
MessageBoxW(nullptr, Ui().adminRequired, Ui().title, MB_OK | MB_ICONWARNING);
}
return 1;
}
std::vector<std::wstring> log;
bool ok = ApplyCore(enable, !noProtection, log);
if (!quiet) {
std::wstringstream stream;
for (const std::wstring& line : log) {
stream << line << L"\n";
}
MessageBoxW(nullptr, stream.str().c_str(), Ui().title,
MB_OK | (ok ? MB_ICONINFORMATION : MB_ICONWARNING));
}
return ok ? 0 : 2;
}
这里返回 -1 表示没有命令行动作,需要继续进入 GUI;返回 0/1/2 表示命令行模式已经处理完毕。
0x0F 资源与图标
资源脚本很小:
#include <windows.h>
#include "resource.h"
IDI_APP ICON "UpdateProhibited.ico"
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x3fL
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "CompanyName", "UpdateProhibited"
VALUE "FileDescription", "UpdateProhibited"
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "UpdateProhibited.exe"
VALUE "OriginalFilename", "UpdateProhibited.exe"
VALUE "ProductName", "UpdateProhibited"
VALUE "ProductVersion", "1.0.0.0"
END
END
END
0x10 构建验证
当前项目已验证两个 Release 配置:
x64 Release: Build succeeded, 0 Warning(s), 0 Error(s)
x86 Release: Build succeeded, 0 Warning(s), 0 Error(s)
输出路径:
UpdateProhibited\x64\Release\UpdateProhibited.exe
UpdateProhibited\Release\UpdateProhibited.exe
当前构建哈希:
x64 SHA256: BFDC6673FE7B66DE44DAB727A372E70675128234D5EB738ED4C9E6B5CA62E477
x86 SHA256: E128CBD62F27236D5E3040B0EFE3AA361D495E631D1B342B3F439C8E89DFC1E6
0x12 总结
UpdateProhibited 的核心思想是:用配置描述目标,用 Win32 API 执行动作,用可逆备份保证恢复路径。
关键技术点包括:
INI Profile API -> 配置驱动
SCM API -> 服务启动类型和状态控制
Registry API -> NoAutoUpdate / IFEO / ImagePath
Task Scheduler COM -> 更新任务计划启停
Toolhelp Snapshot -> 进程枚举和终止
Win32 GUI -> 轻量原生界面
UTF-16 + \uXXXX -> 稳定中英文 UI
从工程角度看,最重要的不是某一个 API,而是几个模块之间的恢复顺序:
Enable Updates:
1. 删除更新策略
2. 恢复服务 ImagePath
3. 恢复服务启动类型
4. 启用任务计划
5. 删除 IFEO Debugger
Disable Updates:
1. 写入更新策略
2. 停止服务
3. 禁用服务启动类型
4. 阻断服务 ImagePath
5. 禁用任务计划
6. 关闭相关进程
7. 写入 IFEO Debugger 阻断
程序开源地址:https://github.com/summer581/UpdateProhibited