Scheduled task and environment variables

  • Thread starter Thread starter Chester
  • Start date Start date
C

Chester

Hi,

I read in a previous post someone mention that when a process is run
from scheduled task, the process is not aware of any environment
variables. For example, the PATH variable is not set properly so a
scheduled process would not have a proper PATH. The thing is on some
computers scheduled task seems to be aware of environment varibales
and on other computers it does not. My question is: how can I fix
this so that on all computers the scheduled task is aware of
environment variables.

Thanks,
Chester
 
Hi,

If you run the Task scheduler under the local system
account then all machine environment variables should be
available. If you are running it as a user account then
more will be available.

I would try a quick test by runing a batch file (via the
scheduler) much like the one below:

------Start------------------
@echo off
path > c:\temp\path.txt
set > c:\temp\set.txt
------Finish-----------------

This way you can see what variables are actually in use.

Regards,

Tim
 
After checking what env. variables you have, you should
modify your batch files and add lines that will set such variables
to what you want them to be. Example:

@echo off
set copycmd=/y
set path=%path%;c:\tools
 
If I run the below batch file in scheduled task, the path is null and
set doesn't list out path variable.

If I run the batch in cmd prompt directly, the path is what you'd
expect, having winNT dir and all kinds of other paths.

This is the problem I was talking about.
 
Chester said:
If I run the below batch file in scheduled task, the path is null and
set doesn't list out path variable.

If I run the batch in cmd prompt directly, the path is what you'd
expect, having winNT dir and all kinds of other paths.

This is the problem I was talking about.

Chester, there are 3 rules of thumb I follow when running processes
under the built in scheduler:

1) Make sure the user context has rights to everything the process needs
to access
2) Never assume anything about environment variables since they may or
may not be available to the process
3) Make sure to fully qualify all file system object references because
2 implies that the path environment variable may or may not be what you
expect or hope it to be.
 
Back
Top