When attempting to execute a file move operation through Windows Task Scheduler on Server 2008 R2, you might encounter the cryptic error 2147942402. This hexadecimal value translates to 0x80070002 in HRESULT, which means "The system cannot find the file specified." However, the reality is more nuanced when dealing with scheduled tasks.
The key difference lies in execution context. While running move C:\Windows\Temp\*.foo E:\Foo_blah_blah_blah_blah\Foo2\
manually works, Task Scheduler operates under different conditions:
// Problematic Task Scheduler configuration:
Action: Start a program
Program/script: move
Arguments: C:\Windows\Temp\*.foo E:\Foo_blah_blah_blah_blah\Foo2\
Three main factors typically cause this error in scheduled file operations:
- Working directory not properly set (Task Scheduler defaults to system32)
- Path length limitations in older Windows versions
- Environment variables not being expanded
Here's the most robust approach using a batch script wrapper:
@echo off
setlocal enabledelayedexpansion
:: Set source and destination
set SOURCE=C:\Windows\Temp\*.foo
set DEST=E:\Foo_blah_blah_blah_blah\Foo2\
:: Verify paths exist
if not exist "%SOURCE%" (
echo Error: Source files not found >&2
exit /b 1
)
if not exist "%DEST%" (
mkdir "%DEST%"
if errorlevel 1 (
echo Error: Could not create destination >&2
exit /b 1
)
)
:: Perform the move
move /Y "%SOURCE%" "%DEST%"
if errorlevel 1 (
echo Error: Move operation failed >&b 2
exit /b 1
)
exit /b 0
When configuring your task:
- Set "Start in" to a valid directory (C:\Windows\System32 works)
- Run with highest privileges
- Set the task to "Run whether user is logged on or not"
- For Server 2008 R2, consider enabling "Do not store password" for the account
For more robust file operations, consider this PowerShell script:
try {
$source = "C:\Windows\Temp\*.foo"
$dest = "E:\Foo_blah_blah_blah_blah\Foo2\"
if (-not (Test-Path $dest)) {
New-Item -ItemType Directory -Path $dest -Force | Out-Null
}
Get-ChildItem $source | Move-Item -Destination $dest -Force
exit 0
}
catch {
Write-Error $_.Exception.Message
exit 1
}
To diagnose the exact failure point:
- Add logging to your batch/PowerShell script
- Check Task Scheduler history (Event ID 201 for actions)
- Test with absolute paths for both source and destination
- Verify account permissions with
whoami /priv
When attempting to automate file operations through Windows Task Scheduler, error 2147942402 typically indicates a file system permission or path resolution problem. In this specific case, we're dealing with a failed attempt to move *.foo files from C:\Windows\Temp to a network location.
This error code translates to 0x80070002 in hexadecimal, which corresponds to ERROR_FILE_NOT_FOUND in the Windows API. However, in Task Scheduler contexts, it often manifests when:
- The working directory isn't properly set
- Environment variables resolve differently under scheduled tasks
- The command interpreter path isn't explicitly specified
The immediate solution would be to modify the task configuration:
Program/script: cmd.exe
Add arguments: /c move "C:\Windows\Temp\*.foo" "E:\Foo_blah_blah_blah_blah\Foo2\"
Key improvements in this approach:
- Explicitly calls cmd.exe as the interpreter
- Uses /c switch for proper command termination
- Properly quotes paths containing spaces
For more robust file operations, consider using PowerShell:
Program/script: powershell.exe
Add arguments: -Command "Move-Item -Path 'C:\Windows\Temp\*.foo' -Destination 'E:\Foo_blah_blah_blah_blah\Foo2\' -Force"
Even when running as Administrator, scheduled tasks have different security contexts. Verify:
- The "Run with highest privileges" checkbox is selected
- The account has explicit permissions on both source and destination
- Network paths are accessible via UNC (\\server\share format)
Create a test batch file to log environment details:
@echo off
whoami /all > "E:\task_debug.log"
set >> "E:\task_debug.log"
dir "C:\Windows\Temp\*.foo" >> "E:\task_debug.log"
move "C:\Windows\Temp\*.foo" "E:\Foo_blah_blah_blah_blah\Foo2\" >> "E:\task_debug.log" 2>&1
When setting up file move operations in Task Scheduler:
- Use full paths for both executable and arguments
- Set "Start in" directory to a writable location (like %SystemRoot%)
- Enable task history for debugging (Task Scheduler → Enable All Tasks History)
- Consider using SYSTEM account if domain permissions are complex