Reading 64 bit registry from 32 bit application and the other way around

Our bootstrapper installation is 32 bit while we install several 64 bit installation like SQL 2008.

We had a requirement to support installing SQL to different port , and apparently this is not supported as a command line / update INI for the installation of SQL.

The only solution is to update the registry (64 bit) of SQL with the new port number and restart services.

We decided to write the code in VBS (or PS) and the way to do it was to use the following (example):

dim objCtx, objLocator, Inparams, Outparams

Const HKLM = &h80000002
Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
objCtx.Add "__ProviderArchitecture", 64 ' Could be 32
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
Set objStdRegProv = objServices.Get("StdRegProv")

Set Inparams = objStdRegProv.Methods_("GetStringValue").Inparameters
Inparams.Hdefkey = HKLM
Inparams.Ssubkeyname = "Software\SomeKey"
Inparams.Svaluename = "SomeNodename"
set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx)

'show output parameters object and the registry value HKLM\SOFTWARE\
WScript.Echo "Value = " & Outparams.SValue



If you try simple approach of load the registry you will automatically get redirected to the 32 but registry! so beware and aware for this.

Reading 64 bit registry from 32 bit application and the other way around Reading 64 bit registry from 32 bit application and the other way around Reviewed by Ran Davidovitz on 1:08 PM Rating: 5

No comments:

Powered by Blogger.