Is it safe to call Regsvr32 concurrently?

4

I have about 100 dll's I need to register with regsvr32 /s some.dll, do I need to wait for each call to regsvr32 to finish before I do the next call or can I just run them all at the same time.

Basically I have the Powershell script

if([System.Environment]::Is64BitOperatingSystem)
{
    $regsvr = [System.Environment]::ExpandEnvironmentVariables('%windir%\SysWOW64\regsvr32.exe')
}
else
{
    $regsvr = [System.Environment]::ExpandEnvironmentVariables('%windir%\System32\regsvr32.exe')
}

foreach( $file in $filesToRegister)
{   
    Write-Verbose "$regsvr /s ""$file"""
    Start-Process $regsvr -ArgumentList '/s', """$file""" -Wait
}

All of the files that are being registered are vb6 dll files that are generated by a large project. Do i need to have the -Wait on my Start-Process or is it safe to take it off?

Scott Chamberlain

Posted 2016-09-29T19:07:43.017

Reputation: 28 923

It would be quite amusing of the process didn't take any necessary safety measures automatically. :D That being said, you'll probably want some kind of success/failure reporting. – Daniel B – 2016-09-29T19:12:22.267

@DanielB that really is my question, does it or does it not take those safety mesures automaticly? – Scott Chamberlain – 2016-09-29T19:12:59.430

I would guess that no, registering would not be thread-safe. just a hunch, it may correctly synchlock the resource its registered in (the registry I imagine) but I wouldn't bet on it. – Frank Thomas – 2016-09-29T19:27:28.227

I've registered 10 or 15 DLL's at a time using a CMD (batch) file without issue. To get error reporting with it, there was PAUSE at the end, so I could read the issues (some DLL's did not have an entry point fro registration, for example, which was inconsequential). – DrMoishe Pippik – 2016-09-29T19:33:43.017

Answers

3

After playing around a bit I discovered that regsvr32 lets you pass in more than one file at a time. Switching $filesToRegister to use relative paths to get the total length of the argument list down and I now do

if([System.Environment]::Is64BitOperatingSystem)
{
    $regsvr = [System.Environment]::ExpandEnvironmentVariables('%windir%\SysWOW64\regsvr32.exe')
}
else
{
    $regsvr = [System.Environment]::ExpandEnvironmentVariables('%windir%\System32\regsvr32.exe')
}

Set-Location $currentBuildFolder
$arguments = @('/s') + $filesToRegister
Write-Verbose "$regsvr $arguments"
Start-Process $regsvr -ArgumentList $arguments -Wait

And it completes much much faster.

Scott Chamberlain

Posted 2016-09-29T19:07:43.017

Reputation: 28 923

Are you sure that regsvr32 works with multiple files in one go? I don't see any reference other than "dllname" on Technet: https://technet.microsoft.com/en-us/library/bb490985.aspx [for XP, but syntax doesn't seem to have changed], and https://support.microsoft.com/en-us/help/249873/how-to-use-the-regsvr32-tool-and-troubleshoot-regsvr32-error-messages

– CJBS – 2017-07-11T19:29:07.960

Yes i am sure, remove the /s and you will get a dialog box per filename you passed in. – Scott Chamberlain – 2017-07-11T23:59:39.487