Get Registry Key at 64Bit OS

Sep 28, 2010 at 2:28 PM


i would like to get the value from a registry key from HKLM\Software\Microsoft\...

But if i take the Extension Pack Tasks, he went to HKLM\Software\Wow6432Node\Software.....

I take the 3.5.7 Installpackage.

I hope somebody can help me,



Sep 29, 2010 at 9:35 AM

You're experiencing Registry re-direction. In 4.0 its easy to get around this with the new RegistryView property. In 3.5 I think you are going to have to exec out to the 64bit msbuild to get the value.


Sep 29, 2010 at 10:14 AM

Hello Mike,

We can not use Framework 4.0 at our company, very bad.

That means, i have to taekt the 3.5 version from the extension pack!

You write:

In 3.5 I think you are going to have to exec out to the 64bit msbuild to get the value.

Can you explane me what you mean with an example, just now, i don't know what you mean,

Thanks for your help,


Sep 29, 2010 at 1:45 PM

It depends what you need to do wiht the value. If you just need to read it and can do stuff in the same target, then its easy. If not, you need to find a way of getting that value back to the other process. In the sample below I use a User environment variable.


<Project ToolsVersion="3.5" xmlns="">
  <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks"/>
  <Target Name="Default">
    <!-- Read the 32Bit registry key -->

    <!-- Reset the temp environment variable we use to get data across processes -->
    <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="MyValue" Value="$(My64Value)" Target="User"/>

    <!-- Exec out to 64Bit MSBuild to read the 64Bit key -->
    <Exec Command="$(windir)\Microsoft.NET\Framework64\v3.5\msbuild.exe /nologo /v:m /t:Get64BitData &quot;$(MSBuildProjectFullPath)&quot;" WorkingDirectory="$(MSBuildProjectDirectory)"/>
    <!-- Read the value from the user enviornment variable-->
    <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Get" Variable="MyValue" Target="User">
      <Output PropertyName="EnvValue" TaskParameter="Value"/>

    <!-- List what we have found -->
    <Message Text="32 Value: $(My32Value)"/>
    <Message Text="64 Value: $(EnvValue)"/>

  <!-- This target is called by the 64 bit process -->
  <Target Name="Get64BitData">
    <Message Text="Hi from 64Bit mode" Importance="high"/>
    <!-- Read the 64Bit registry key -->

    <Message Text="64 Value: $(My64Value)" Importance="high"/>
    <!-- Assign the value to our temp user environment variable -->
    <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="MyValue" Value="$(My64Value)" Target="User"/>

Hope that helps.



Sep 29, 2010 at 1:46 PM

Please note that you will have to copy the ExtensionPack installation folder from Program Files (x86) to Program Files so the 64 bit process works.

Oct 2, 2010 at 7:01 AM

Hello Mike,

thank you, that's it, it works fine :-)


Oct 11, 2011 at 3:52 PM


Is it normal that the env vat isn't available for further use i.e. after leaving the script's scope ?

My test was the following :

I have the following script :


<Project xmlns="">
    <Import Project="C:\Program Files\MSBuild\ExtensionPack\MSBuild.ExtensionPack.tasks"/>
    <Target Name="Default" >
        <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="TEST" Value="Hello" Target="User" />


And the following batch file :

call "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"
call C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe version.xml
echo %TEST%

I was expecting the batch to echo "Hello" but it didn't...

Oct 11, 2011 at 5:22 PM

When the cmd runs, the user envars are read (cached). you need a new process to then read that value.