Can a Windows scheduled task update itself and how would I do it?

1

Can a Windows scheduled task update itself and how would I do it? I'm using Windows Server 2008. I've seen some Powershell scripts that create tasks from xml; would this be the right approach?

Jaco Briers

Posted 2012-07-26T07:35:53.560

Reputation: 111

Answers

0

Are you trying to change the Task itself, for example, changing the trigger? If so, Take a look into

SCHTASKS /CHANGE /?

If your task executes some kind of script, then you can include a call to that command on it. However, this would need the run account password (/RP) to be supplied interactively IF your are not using the system, local service or network service account. A DANGEROUS technique you can use is calling this and redirecting the input to a file storing the password, like this:

SCHTASKS /CHANGE /TN YOR_TASK_NAME /RU RUN_USER < FILE_WITH_CLEARTEXT_PASSWORD

So, if your task can run fine with the network service or local service account then go ahead use them. Some people might be wary of using the SYSTEM account, but then again, storing the password in a clear text file seems like a worse option.

Kemuel Sanchez

Posted 2012-07-26T07:35:53.560

Reputation: 101

It seems to me that the other answer is probably much closer to what the asker wanted to know. The idea was most likely to run a self-updating script, not how to change a scheduled task. – Julie Pelletier – 2016-08-19T00:37:25.777

Maybe so, however since it isn't clear and I do see some value on the idea of modifying the task itself (who knows, changing triggers, etc etc) that's why I asked. It's still up to the OP to let us know what the really needed :) – Kemuel Sanchez – 2016-08-20T14:55:41.483

0

You mean update the command that it runs? I suppose so. To summarize:

You schedule a script (I like powershell) that does what you really need done but also checks for newer versions of itself at some central location, and if it's newer then it copies that down to where the scheduled task looks to run the script. OR, it could reimport the scheduled task xml from another location, either way you want to script it.

MDMoore313

Posted 2012-07-26T07:35:53.560

Reputation: 4 874