Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 450
Lei Yang Avatar asked Dec 11 '22 17:12

Lei Yang


1 Answers

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)"
}
like image 172
Mathias R. Jessen Avatar answered Mar 22 '23 23:03

Mathias R. Jessen