MCPcopy Create free account
hub / github.com/WavesMan/Disable-automatic-Windows-update / disable

Method disable

python/core/services.py:148–175  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

146 self.registry = registry
147
148 def disable(self) -> Result:
149 start = time.perf_counter()
150 log_event(logging.INFO, "onedrive_disable_started", "开始禁用 OneDrive", action="disable_onedrive", status="started")
151 # NOTE: 采用组策略键的双路径写入提高可靠性,并移除当前用户自启动项,减少自动拉起;
152 # 同时尝试结束相关进程(若不存在则容错忽略)
153 cmds = [
154 'taskkill /F /IM OneDrive.exe',
155 'taskkill /F /IM OneDriveStandaloneUpdater.exe',
156 f'reg add "{ONEDRIVE}" /v "DisableFileSyncNGSC" /t REG_DWORD /d 1 /f',
157 f'reg add "{ONEDRIVE_WIN_POLICY}" /v "DisableFileSync" /t REG_DWORD /d 1 /f',
158 'reg delete "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" /v "OneDrive" /f',
159 ]
160 ok, errors = self.registry.batch(cmds)
161 duration_ms = int((time.perf_counter() - start) * 1000)
162 if ok:
163 log_event(logging.INFO, "onedrive_disable_finished", "禁用 OneDrive 成功", action="disable_onedrive", status="ok", duration_ms=duration_ms)
164 return Result(True, data={"status": "disabled"})
165 log_event(
166 logging.ERROR,
167 "onedrive_disable_finished",
168 "禁用 OneDrive 失败",
169 action="disable_onedrive",
170 status="failed",
171 duration_ms=duration_ms,
172 error_type="REGISTRY_WRITE_FAILED",
173 error_message="; ".join(errors),
174 )
175 return Result(False, error={"code": "REGISTRY_WRITE_FAILED", "message": "部分键写入失败", "details": errors})
176
177 def enable(self) -> Result:
178 start = time.perf_counter()

Callers

nothing calls this directly

Calls 3

log_eventFunction · 0.85
ResultClass · 0.85
batchMethod · 0.80

Tested by

no test coverage detected