When dealing with legacy applications in scheduled tasks, we often encounter scenarios where processes appear to launch but fail to execute their core functionality. In your case, the EXE modifies files when run interactively but becomes a "phantom process" when executed through Task Scheduler.
// Diagnostic PowerShell snippet to verify actual process execution
Get-WinEvent -LogName Microsoft-Windows-TaskScheduler/Operational |
Where-Object {$_.Id -eq 129} |
Select-Object -Last 10 |
Format-Table TimeCreated, Message -AutoSize
This specific error code (0x800705B3) translates to "This operation returned because the timeout period expired." This suggests the task scheduler is waiting for something that never completes. For GUI applications, this typically means:
- Missing interactive desktop session
- Dependencies on user profile components
- Hidden message boxes waiting for input
Your C# wrapper approach was correct in principle, but might need additional handling:
// Enhanced C# launcher with error redirection
var psi = new ProcessStartInfo
{
FileName = "legacyapp.exe",
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (var process = Process.Start(psi))
{
process.WaitForExit(30000); // 30s timeout
if (!process.HasExited)
{
process.Kill();
Environment.Exit(1);
}
string errors = process.StandardError.ReadToEnd();
if (!string.IsNullOrEmpty(errors))
{
File.WriteAllText(@"C:\temp\legacyapp_error.log", errors);
}
}
Windows Server 2008 R2 introduced session isolation that can break GUI applications. Try these registry modifications (requires reboot):
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows]
"NoInteractiveServices"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager]
"ProtectionMode"=dword:00000000
When traditional scheduled tasks fail, consider:
- PowerShell Workflow:
- Windows Service Wrapper using NSSM (Non-Sucking Service Manager)
- AutoIT Script for GUI automation
workflow Run-LegacyApp {
inlinescript {
Start-Process "legacyapp.exe" -WindowStyle Hidden -Wait
}
}
Register-ScheduledJob -Name LegacyAppRunner -ScriptBlock {
Run-LegacyApp
} -Trigger (New-JobTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Hours 1))
When all else fails, use Process Monitor to capture what's actually happening:
1. Download ProcMon from Sysinternals
2. Set filter: Process Name is legacyapp.exe
3. Run task manually through scheduler
4. Analyze file/registry/network access attempts
5. Pay special attention to ACCESS DENIED errors
When dealing with legacy applications in scheduled tasks, one common pitfall is the interaction between GUI processes and the Windows Task Scheduler service. The key symptom here is that the EXE runs manually but fails silently when executed through the task scheduler.
Converted to hex (0x800705B3), this corresponds to ERROR_PIPE_NOT_CONNECTED. This typically indicates:
- Session isolation between the service account and interactive desktop
- Missing desktop heap allocation
- Permission issues with Windows Station/Desktop objects
1. Configure the Task for Interactive Mode
Modify your scheduled task with these settings:
schtasks /change /TN "YourTaskName" /IT
Or through GUI:
- Check "Run only when user is logged on"
- Enable "Run with highest privileges"
2. Use PowerShell Wrapper Script
Create a wrapper that handles the GUI session requirement:
# Save as RunLegacyApp.ps1
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = "C:\path\to\your.exe"
$psi.Arguments = "/silent"
$psi.UseShellExecute = $true
$psi.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
$process = [System.Diagnostics.Process]::Start($psi)
$process.WaitForExit()
3. Modify Registry for Desktop Heap
Warning: Registry modifications can affect system stability. Create a backup first.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems]
"Windows"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,\
74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,63,\
00,73,00,72,00,73,00,73,00,2e,00,65,00,78,00,65,00,20,00,4f,00,62,00,6a,00,\
65,00,63,00,74,00,44,00,69,00,72,00,3d,00,25,00,53,00,79,00,73,00,74,00,65,\
00,6d,00,52,00,6f,00,6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,\
6d,00,33,00,32,00,20,00,53,00,68,00,61,00,72,00,65,00,64,00,53,00,65,00,63,\
00,74,00,69,00,6f,00,6e,00,3d,00,31,00,30,00,32,00,34,00,20,00,53,00,68,00,\
61,00,72,00,65,00,64,00,57,00,69,00,6e,00,64,00,6f,00,77,00,3d,00,31,00,30,\
00,32,00,34,00,20,00,53,00,68,00,61,00,72,00,65,00,64,00,43,00,6f,00,6e,00,\
73,00,6f,00,6c,00,65,00,3d,00,31,00,30,00,32,00,34,00,20,00,53,00,68,00,61,\
00,72,00,65,00,64,00,4d,00,6f,00,75,00,73,00,65,00,3d,00,31,00,30,00,32,00,\
34,00,20,00,4d,00,61,00,78,00,43,00,6f,00,6e,00,73,00,6f,00,6c,00,65,00,53,\
00,63,00,72,00,65,00,65,00,6e,00,73,00,3d,00,31,00,30,00,20,00,4d,00,61,00,\
78,00,48,00,69,00,74,00,73,00,3d,00,35,00,30,00,30,00,20,00,4c,00,61,00,6d,\
00,70,00,53,00,74,00,61,00,72,00,74,00,3d,00,31,00,30,00,30,00,30,00,30,00,\
20,00,4c,00,61,00,6d,00,70,00,4f,00,66,00,66,00,3d,00,31,00,30,00,30,00,30,\
00,30,00,20,00,4c,00,61,00,6d,00,70,00,53,00,70,00,65,00,63,00,75,00,6c,00,\
61,00,72,00,3d,00,31,00,30,00,30,00,30,00,30,00,20,00,53,00,70,00,6f,00,6f,\
00,6c,00,3d,00,79,00,65,00,73,00
Modify the SharedSection values (1024,1024,1024) - the third value controls non-interactive sessions.
For persistent legacy applications, consider using NSSM (Non-Sucking Service Manager):
nssm install LegacyAppService
nssm set LegacyAppService Application "C:\path\to\your.exe"
nssm set LegacyAppService AppParameters "/silent"
nssm set LegacyAppService AppDirectory "C:\path\to"
nssm set LegacyAppService AppExit Default Exit
nssm start LegacyAppService
Use Sysinternals Process Monitor to capture the execution attempt:
- Set filter: Process Name is "your.exe"
- Run the scheduled task
- Analyze the captured operations for access denied errors or missing dependencies