Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an executable that needs to be run on an E:/ drive, Windows Server 2012 is installed on the C:/ drive. I've created a scheduled task that has the full path to the target executable (E:/stuff/target.exe), and has the working directory set (E:/stuff/).

This fails, task scheduler tells me that the directory name is invalid. If i remove the working directory, it tells me access is denied. This can't be right, The entire drive is both shared, and has file permissions set to "everyone" with full control. The account running the task can definitely run it (i can do so through cmd.exe). Sidenote: I've tried all permutations of the path, using backslashes, forward slashes, quotes, and non-quotes. This is not due to KB2452723.

I've tried having a batch file which uses "CD" to set the working directory to E:/stuff/, then call the program, which works when i run it. Unfortunately, when run through Task Scheduler, it never changes the working directory, and tries to call target.exe from the system drive (where it doesn't exist).

I've also tried making a symbolic link ("mklink /D") from C:/temp/ to E:/stuff/, in the vain hope that i could fool task scheduler, but it won't follow the link, and tells me that the directory could not be found.

I cannot figure out why task scheduler would fight this so hard, nor what the correct practice would be to get this to work. Has anyone successfully run a file on a non-system drive with task scheduler?

share|improve this question
    
Is this E: drive a network mapped drive? –  afrazier Jul 22 '13 at 0:31
    
It's a local drive. I should have mentioned, this is running on a VM, so it's probably actually the same physical drive as the C: drive. –  Knetic Jul 22 '13 at 0:41
    
A few requests, can you do the command NET USE from a command prompt and copy the output here, also can please run icacls E:/stuff and copy the output of that too? (please edit your question with these updates, don't post them as comments) –  Scott Chamberlain Jul 22 '13 at 2:56

2 Answers 2

Drive mappings aren't seen by services or tasks. Use an UNC path instead.

\\server\share\directory\someprogram.exe

Another option is to schedule a batch file to run and include a drive mapping there. In a batch file it is easier to use pushd/popd to map without worrying about what drive letter it gets (pushd can map to a drive letter and switch to that drive letter, popd can unmap and return to the previous drive letter).

pushd \\server\share
\directory\someprogram.exe
popd
share|improve this answer
    
Didn't work, it stated that access was still denied, even when using the UNC path (i also tried using the admin share path, e.g., "\\localhost\E$\stuff") When i ran a command window as the same service account that is being used by the scheduled task, and ran the same pushd/popd commands, it worked as expected. Only when running through task scheduler did it fail. –  Knetic Jul 22 '13 at 18:02

After banging head against wall for a few hours, i found a solution. It appears that in Server 2012, scheduled tasks cannot touch directories which do not have explicit allow permissions for the account you're using to run the file. It doesn't matter if that account is in a group which is allowed into the directory.

e.g., If i want to run E:/stuff/target.exe using account THINGS\svcAccount , then THINGS\svcAccount must be given explicit full control over E:/stuff in order to run. I had assumed that if THINGS\svcAccount was in the administrators group, and the administrator group had full control over E:/stuff, it would inherit permissions. Server 2012 does not do that.

This only seems to apply to scheduled tasks - running a command window or a powershell window as THINGS\svcAccount works exactly as expected.

share|improve this answer
    
I wonder if there's some checkbox to toggle in the scheduled task definition to control this behavior –  afrazier Jul 23 '13 at 1:09
    
If svcAccount is in the Administrators group, then just ticking the "Run with highest privileges" checkbox should enable it to access the path via its Administrator membership. –  romkyns Oct 27 at 0:37

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.