Alien-47
Alien-47

Reputation: 323

How to make powershell tell me about missing DLLs?

I use powershell as shell in Windows. When I'm trying to launch some application who's dll dependencies are missing in PATH environment variable, then nothing happens, powershell just silently returns with new command prompt.

Is there a way to make powershell fail louder, telling me what exactly is missing, like default cmd shell does?

Upvotes: 18

Views: 2826

Answers (3)

Shaqil Ismail
Shaqil Ismail

Reputation: 1959

You could echo the %ERROR% variable, which stores errors until the PowerShell window is closed.

Update: In PowerShell, you could use the Get-Error command, or look at the $Error variable.

Another way would be to use Dependancy walker, if you can use a command line option, then you should be able to use this in PowerShell.

Upvotes: -2

Iwan Aucamp
Iwan Aucamp

Reputation: 1705

I was having this same problem. PowerShell was setting $LASTEXITCODE code to -1073741515 (0xC0000142, 3221225794) but no output explaining what was actually wrong. When running it via cmd.exe I would get popup with something like:

The code execution cannot proceed because some.dll was not found. Reinstalling the program may fix this problem.

cygwin bash outputs errors relating to dll not found to stderr and if you run the the same via bash from PowerShell then you can see the error:

> & 'C:\tools\cygwin\bin\bash.exe' '-c' '"C:/Users/xxx/dir/main.exe"'
C:/Users/xxx/dir/main.exe: error while loading shared libraries: another.dll: cannot open shared object file: No such file or directory

This works with git bash also:

> & 'C:\Program Files\Git\bin\bash.exe' '-c' '"C:/Users/xxx/dir/main.exe"'
C:/Users/xxx/dir/main.exe: error while loading shared libraries: another.dll: cannot open shared object file: No such file or directory

Quite a hack but better than nothing.

Upvotes: 7

NoWar
NoWar

Reputation: 37633

I am afraid there is no way to get that info... But try to read

An Introduction to Error Handling in PowerShell http://blogs.msdn.com/b/kebab/archive/2013/06/09/an-introduction-to-error-handling-in-powershell.aspx

or PowerShell Tutorial – Try Catch Finally and error handling in PowerShell http://www.vexasoft.com/blogs/powershell/7255220-powershell-tutorial-try-catch-finally-and-error-handling-in-powershell

Try
{
    $AuthorizedUsers = Get-Content \\ FileServer\HRShare\UserList.txt -ErrorAction Stop
}
Catch [System.OutOfMemoryException]
{
    Restart-Computer localhost
}
Catch
{
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
    Send-MailMessage -From [email protected] -To [email protected] -Subject "HR File Read Failed!" -SmtpServer EXCH01.AD.MyCompany.Com -Body "We failed to read file $FailedItem. The error message was $ErrorMessage"
    Break
}
Finally
{
    $Time=Get-Date
    "This script made a read attempt at $Time" | out-file c:\logs\ExpensesScript.log -append
}

Upvotes: -4

Related Questions