Windows Task Scheduler – Access Environment Variables in Scheduled Task

scheduled-taskstask schedulerwindows

When setting up a scheduled task, for the action section I'm trying to access an environment variable for the location of the executable that I wish to run. This is mainly because on one machine the executable could be in C: on another it could be on D: I've verified that if I use a hard coded path my scheduled task runs, but if I change the action to point to "%MyAppPath%\MyApp.exe" the task won't start suffering a launch failure. I've verified that the environment variable is set up.

Is it even possible inside the action (and working directory) part of task schedule to reference an environment variable – is my syntax wrong.

On a side note, I did think about calling a BAT file and referencing the environment variable there, but that doesn't solve anything for me as the main issue is actually knowning whether the application (and the bat file too) is on C: or D: drives – inside the drive itself the path is the same.

UPDATE: It turns out you can use them with a machine reboot but perhaps there is a better way

Best Answer

You do not need a machine reboot. You should terminate Taskeng.exe and the next time scheduled task is run it will get an updated environment.

Related Question