PowerShell / PowerShell-Native

MIT License
50 stars 33 forks source link

Running win32 application from shell "exits silently" but in reality crashes on load #31

Open thlac opened 5 years ago

thlac commented 5 years ago

So I ran into an issue where an application unexpectedly would no longer launch when called directly from the shell, i.e. ".\appname.exe"

After troubleshooting for a bit with my trusty old friend Process Monitor, I could see the process opening and closing down again, looking at the Process Exit event, I saw the exit code of -1073741515 (aka. 0xC0000135, aka. STATUS_DLL_NOT_FOUND)

That was a quite easy fix, but it nagged me that I got no indication of the failure, in any other circumstance (running from cmd, double-clicking in explorer, run or even in powershell with Start-Process) a message would pop up stating a DLL was missing, and which one it was.

(I don't know if this issue extends to Linux/MacOS, or even if it can affect those platform)

Steps to reproduce


- First and foremost, a win32(native) application is needed with a linked library that's missing
- PS > .\path\to\executable.exe

Expected behavior

External System Error prompt

Actual behavior

No Output

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
SteveL-MSFT commented 5 years ago

Need more info, is this ia native app or managed app?

thlac commented 5 years ago

Sorry, that's what I meant by win32, it's a fully native app. I've edited the original post to reflect this.

thlac commented 5 years ago

I can't share the program in question, but you can download something like quassel for win64(irc client), and delete qt5gui.dll to get the same effect.

lzybkr commented 5 years ago

If you run the same program from cmd.exe, I'm guessing you'll get a popup about a dll that can't be found.

Assuming so, the cause is this line of code.

You can use P/Invoke to enable popups - see the docs on SetErrorMode. Personally I think the error mode should be 0 instead of SEM_FAILCRITICALERRORS, but I can see reasonable people wanting the current behavior. At a minimum though, I think any interactive commands should display the popup.

thlac commented 5 years ago

Yep, that's exactly it, you get an error dialog if you run it in any other way.

I also agree that we probably only want the behaviour interactively, though I'm not sure how the behaviour would be while headless or in a Windows Nano Server setting.