Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a scheduled task, a batch file, that uses an environment variables which is set system-wide.

On server 1, the scheduled task runs under a domain account and the environment variable works. The environment variable also exists in my session and when I runas as the service account.

On server 2, the scheduled task runs under a different domain account and the environment variable DOES NOT work. However, the environment variable does exist in my session and when I runas as the service account.

On both servers the environment variable has been set system-wide by the same script originally. The script runs again every now and then and as far as I can see noone has tempered with the environment variable.

The scheduled tasks are set up identically on the two servers (using the same XML file) and the two service accounts are identically configured (as far as I know).

What am I doing wrong?

share|improve this question
1  
What is the error code returned by scheduled task? –  Volodymyr Nov 16 '12 at 9:28
    
It returns whatever error code I tell it to return. The scheduled task is my batch file. –  Andrew J. Brehm Nov 16 '12 at 11:32
    
I mean errors returned by Task Scheduler, under Last Run Result column. If the task is completed successfully - you get 0x0, if Not - something else. –  Volodymyr Nov 16 '12 at 11:42
    
I get the error code my batch file returns. It happens to be 1 since that is what my batch file returns when it finds the environment variable empty. –  Andrew J. Brehm Nov 16 '12 at 13:57
    
have you restarted server 2 after applying environment variables? See this reference –  Volodymyr Nov 16 '12 at 14:02

1 Answer 1

up vote 1 down vote accepted

I solved the problem by allowing the scheduled task to "run with highest privileges" on both servers.

I don't know why that helps but apparently on server 2 the domain account just doesn't see the environment variables when not run with highest privileges.

share|improve this answer
    
Good! Have you tried to use working account on 2nd server to see if it works without "run with highest privileges" ? –  Volodymyr Nov 16 '12 at 15:17
    
No. Each server has a domain account assigned for this purpose. I cannot move them around. I shouldn't even know the password for the account. –  Andrew J. Brehm Nov 16 '12 at 15:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.