Caleb Jares
Caleb Jares

Reputation: 6307

Start-Process : Process with an Id of 5344 is not running

PS C:\> start regedit -ArgumentList '/S', 'D:\resources\hawk_config.reg' -Wait
Start-Process : Process with an Id of 5344 is not running.
At line:1 char:6
+ start <<<<  regedit -ArgumentList '/S', 'D:\resources\hawk_config.reg'
    + CategoryInfo          : NotSpecified: (:) [Start-Process], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.StartProcessCommand

I can't figure out what it is. Any ideas?

Upvotes: 3

Views: 5081

Answers (2)

user2105109
user2105109

Reputation: 1

WaitForExit() will throw a SystemException if the process has already exited.

I get this same thing randomly in a PS script that uses start-process in a loop. never on the same iteration, sometimes never at all. this would explain that behavior perfectly. Random asynchronous timing of threads and processes.

I tried the suggested error message dump and it looks like it confirms the idea that the process is finishing before WaitForExit() gets to see it:

Start-Process : Cannot process request because the process (38152) has exited.

$result = start-process <<<< -filepath $compiler -argumentlist $argstr -nonewwindow -passthru -wait CategoryInfo : NotSpecified: (:) [Start-Process], InvalidOperationException + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

Upvotes: 0

Keith Hill
Keith Hill

Reputation: 201642

Doesn't the /S parameter cause regedit to exit as soon as it's merged the .reg file? I suspect the error you are getting is because regedit has already exited before Start-Process has a chance to call Process.WaitForExit() on the process object. Take a look at the bowels of the error by running $error[0] | Format-List * right after the command. WaitForExit() will throw a SystemException if the process has already exited. I can't repro this on PowerShell v3. Perhaps they fixed an issue with this cmdlet.

As a workaround you could try:

$p = start-process regedit -ArgumentList '/S', 'D:\resources\hawk_config.reg' -passthru
$p.WaitForExit()

Upvotes: 3

Related Questions