共用方式為


Don't shoot the messenger(s)

I had some .lnk files in my docs that pointed to some .wiq files I use a good bit.  I tried to execute one of them from PowerShell today and got an odd message.  As it turns out, the cause was that the target of the .lnk had been deleted, but you couldn't tell from this error message :)

So I thought about emailing the PowerShell alias, but then I checked to see where the exception was coming from.  Many thanks to Jim Truher for showing me this one on a previous issue I was having.

So PowerShell is just propagating the Win32Exception from Process.Start.  In turn, Process.Start is just propagating a Win32 error of 1223 (ERROR_CANCELLED) from ShellExecuteEx.  The "errors returned" says:

ERROR_CANCELLED
The function prompted the user for additional information, but the user canceled the request.

Most likely, this is because in the usual shell scenario, a UI is indeed invoked when trying to execute a broken .lnk file, and since this particular Process.Start/ShellExecuteEx is likely disallowing that UI, we get into this situation.

Summary: weird behavior from PowerShell doesn't necessarily mean weird behavior by PowerShell :)