Registering .DLL

I have a powershell script that copies a .dll to C:\Windows\System32 and I am trying to also, in the script, register the .dll. It successfully registers if the path of the .dll is the source folder (C:\Temp) but the .dll doesn’t register when residing in C:\Windows\System32. The script is being run as administrator so permissions are not the issue. I confirmed the registration/non-registration by searching HKCR\Typelib.

Here is my current code:

$Location = Get-Location
$system32 = $env:SystemRoot\system32
Copy-Item -Path "$Location\msvbvm50.dll" -Destination $system32
Set-Location $env:SystemRoot\system32
Start-Process regsvr32.exe "/s msvbvm50.dll"

Can someone, please, provide some tips on how to properly register .DLLs in the system32 folder using a script?

If you remove the /s so that it’s not silent, do you get any errors?

You can just change the last line to

regsvr32.exe /s msvbvm50.dll

I manually ran regsvr32.exe while in the system32 folder and received an error that the .dll failed to load because it might not be found. I then tried it, again, in C:\temp and it worked fine. I am going to try running the script as the system account to see if that works even though admin should have proper rights in the system32 folder.

If you’re on 64-bit Windows the System32 folder may not be the correct path: