Determining Default Working Directory for Scheduled Tasks under SYSTEM Account in Windows Server 2008 R2


3 views

When troubleshooting scheduled tasks that generate output files but don't explicitly specify a working directory, the default location depends on several factors including the Windows version and account context.

For tasks running under the SYSTEM account in Windows Server 2008 R2, the default working directory is typically:

C:\Windows\System32

This differs from user-context tasks which would default to the user's profile directory.

You can confirm this programmatically by creating a test task that outputs its working directory. Here's a PowerShell example:

$taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-Command "Write-Output (Get-Location).Path | Out-File C:\temp\task_working_dir.txt"'
Register-ScheduledTask -Action $taskAction -TaskName "TestWorkingDir" -User "SYSTEM" -RunLevel Highest
Start-ScheduledTask -TaskName "TestWorkingDir"

After running, check C:\temp\task_working_dir.txt to see the actual working directory.

If your task generates output but you can't find it, try these approaches:

1. Search the entire system drive:
dir /s /b output_filename.*
   
2. Check common SYSTEM account write locations:
- C:\Windows\Temp
- C:\Windows\System32
- C:\Windows\SysWOW64 (for 32-bit tasks)

To avoid this issue in future tasks, explicitly specify output paths:

# PowerShell example with explicit path
$taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' 
    -Argument '-Command "YourCommandHere | Out-File C:\explicit\path\to\output.log"' 
    -WorkingDirectory 'C:\explicit\path\to'

For existing tasks where you can't modify the configuration:

# Use Process Monitor to track file operations
procmon.exe /AcceptEula /Quiet /Minimized /BackingFile output.pml

Filter for the task's process name and look for file system write operations.


When a scheduled task runs under the System account in Windows Server 2008 R2 without a specified "Start in" directory, the default working directory typically falls back to:

C:\Windows\system32

This is because the System account inherits the environment variables and security context of the Windows directory structure. The system32 folder becomes the de facto working directory when no explicit path is provided.

To find files generated by your scheduled task, check these common locations:

  • C:\Windows\System32\ (primary default)
  • C:\Windows\SysWOW64\ (for 32-bit processes on 64-bit systems)
  • The root directory of the script being executed (if applicable)

You can verify the working directory programmatically by creating a test task with this PowerShell script:

# Test script to output current directory
$logPath = "C:\Temp\TaskDirectory.log"
"Current working directory: $pwd" | Out-File -FilePath $logPath
Get-ChildItem | Select-Object FullName | Out-File -FilePath $logPath -Append

To avoid uncertainty about output locations:

  1. Always explicitly set the "Start in" field in task properties
  2. Use absolute paths in your scripts
  3. Consider redirecting output to a known location:
schtasks /create /tn "MyTask" /tr "C:\scripts\myscript.bat" /sc DAILY /ru "SYSTEM" /rp /rl HIGHEST /it /v1 /sd 01/01/2023 /ed 12/31/2023 /st 23:00 /f /xml "C:\tasks\mytask.xml"

If you still can't locate output files:

  • Check system event logs for task execution errors
  • Use Process Monitor to track file system activity
  • Verify the SYSTEM account has write permissions to the target directory

For batch files, explicitly set the directory at script start:

@echo off
cd /d "C:\TaskOutputs\"
rem Rest of your script commands