How to make powershell tell me about missing DLLs?

后端 未结 3 534
有刺的猬
有刺的猬 2021-02-06 08:28

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, powersh

相关标签:
3条回答
  • 2021-02-06 08:37

    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.

    0 讨论(0)
  • 2021-02-06 08:51

    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.

    0 讨论(0)
  • 2021-02-06 08:54

    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 ExpensesBot@MyCompany.Com -To WinAdmin@MyCompany.Com -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
    }
    
    0 讨论(0)
提交回复
热议问题