Visual Studio Registry conflict on Terminal Server

Visual Studio has been installed as a TS Aware application.

But when DEVs used the option “register for COM intercop” from Project properties, they started to face Registry conflicts.

In fact, this option calls “regasm.exe” which will register the DLL path into the “HKEY_LOCAL_MACHINE” Windows Registry and leads to conflict as they are used by all users.

They are others solutions to by pass this as the Reg-Free COM using a Manifest file but it was unusable is our case.

So I decided to force VS to register those paths into the “HKEY_CURRENT_USER” Registry using a PowerShell script running on Post-Build.

What will do the script?:

  • Run “regasm.exe” to generate the reg file.
  • Find and replace “HKEY_CLASSES_ROOT” (which is a mixed view of the “HKEY_LOCAL_MACHINE” and others) by “HKEY_CURRENT_USER\Software\Classes”.
  • Run “regedit.exe” to apply the .reg.

Note: I’m using 32bit version of regedit to make sure it registers the keys to Wow6432Node. The path is not present in the .reg file but regedit knows how to handle it properly.

That’s all.

Script to place in your Project “..\bin\Debug” folder (.ps1), just replace A,B,C,D by the name of your DLLs without extension:


ForEach ($i in $dlls) {

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /nologo /codebase "$i.dll" /regfile:"$env:temp\$i.reg"
 (Get-Content "$env:temp\$i.reg") | ForEach-Object { $_ -replace "HKEY_CLASSES_ROOT", "HKEY_CURRENT_USER\Software\Classes" } | Set-Content "$env:temp\$i.reg"
 C:\Windows\syswow64\regedit.exe /s "$env:temp\$i.reg"

VS Post-build event command-line:

Powershell.exe -executionpolicy remotesigned -File script_name.ps1

Find Visual Studio product key from registry

Visual Studio’s product key is stored into the Registry. The path is:

HKEY_LOCAL_MACHINE > SOFTWARE > Wow6432Node > Microsoft > VisualStudio > 11.0 > Registration > 2000.0×0000 > PIDKEY

For info:

11.0 = VS 2012

10.0 = VS 2010

9.0 = VS 2008

8.0 = VS 2005

7.0 = VS .NET