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.

Task Scheduler - I have a .cmd file I'm trying to execute on a regular basis through Task Scheduler. I've set the task so that it points to the cmd file. I want the task to execute even when no one is logged in. I've set the credentials associated with the task to the local service account. When I execute the task, nothing happens. The Last Run Result shows 0x1, this means it didn't execute properly. When I run the file from a command prompt it executes just fine. Any help out there would be appreciated. I would post the code but it has sensitive information in it and I'm not allowed to let the code outside. Thanks

share|improve this question
    
The best way I found to test these issues is to create a task with the same exact setting except it launches the cmd.exe. Mark the task interactive and logon directly to the console. In the cmd shell that opens when the task runs, test your command line from within there. This way you will run in the same context. once you have the issues worked out here including changing the scheduled task settings, your job will likely run correctly. –  uSlackr Aug 12 '11 at 16:24
add comment

5 Answers

For XP, 2000 and Server 2003 take a look at this MS article "the only way to schedule a task as the System Account is to use AT.EXE to schedule the task"

http://support.microsoft.com/kb/223375

For vista and 2008 this may help http://stackoverflow.com/questions/77528/how-do-you-run-cmd-exe-under-the-local-system-account

share|improve this answer
add comment

Make a user account, set permissions so the task can run as that user (e.g. folder access permissions), run a command prompt as that user (runas /user:domain\user cmd) then from there try the task.

When that's working, set the scheduled task to run as that user.

Edit: this wont work until you take into account Shane Madden's reply about permissions on c:\windows\system32\cmd.exe as well.

share|improve this answer
add comment

It's unclear from your question whether the task is running as "LOCAL SYSTEM" or a local user that's a service account.

If,

  1. the user is a local service account, not the system account, and
  2. the user is not in the Administrators group,

then you'll need to make modifications to the security settings of cmd.exe - by default, the NTFS ACL only allows Administrators and interactively logged on users to execute it. (reference)

Edit: Oh, and this is only applicable to Windows 2003. I'm up to three baseless assumptions in this answer.. let us know what OS and level of user rights and we should be able to narrow it down.

share|improve this answer
    
Good point; just checked how I got scheduled tasks running as non administrators - turns out I explicitly gave them read + read&execute permissions on cmd.exe –  TessellatingHeckler Aug 12 '11 at 16:43
1  
@TessellatingHeckler And now that I think about it, we didn't mention the "Run as batch job" user right assignment, either (though it's automatically added by the scheduled tasks GUI tool).. It's a tangled mess of privileges! –  Shane Madden Aug 12 '11 at 16:50
add comment

Try a pause in your script.You will then be able to read the problem.

In my case, I got an access denied error, since the script started running in \windows\system32. So, after changing into the correct folder (cd), it worked.

share|improve this answer
add comment

I had a similar issue because my .cmd file was in C:\ (root). After moving elsewhere, it ran fine from the Task Scheduler. In some corporate environments, there are restrictions at the C:\ root level.

share|improve this answer
add comment

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.