Search code examples
powershellregsvr32

Powershell to display Regsvr32 result in console instead of dialog


I've searched but did not find any answer.
The task is register one dll using Powershell ps1, followed by other lines of scripts. I don't want to be interrupted by the dialog, so added the /s parameter. But now the result information is ignored, no matter succeed or fail. I want the result displayed in console. But how?


Solution

  • Launch regsvr32.exe /s with Start-Process -PassThru and inspect the ExitCode property:

    $regsvrp = Start-Process regsvr32.exe -ArgumentList "/s C:\path\to\your.dll" -PassThru
    $regsvrp.WaitForExit(5000) # Wait (up to) 5 seconds
    if($regsvrp.ExitCode -ne 0)
    {
        Write-Warning "regsvr32 exited with error $($regsvrp.ExitCode)"
    }