Reading Data from the Registry

InstallShield 2020

Basic MSI Project

The AppSearch and RegLocator tables can read a value from the registry. To read the RegisteredOwner value mentioned above, add the following record to the AppSearch table, using the Direct Editor:

Values for the AppSearch Table

Field

Value

Comments

Property

REGISTERED_OWNER

Must be a public property

Signature_

registry_sig

 

Next, add the following record to the RegLocator table:

Values for the RegLocator Table

Field

Value

Comments

Signature_

registry_sig

Same signature as above

Root

2

HKEY_LOCAL_MACHINE

Key

Software\Microsoft\Windows NT\CurrentVersion

 

Name

RegisteredOwner

 

Type

2

Registry data

After the AppSearch action runs, the REGISTERED_OWNER property will contain the data read from the registry. If the value is not found, the property will be undefined (empty).

For more information regarding the AppSearch and RegLocator tables, see the Windows Installer Help Library.

For Windows Installer-based projects, you can use the System Search Wizard to find data.

InstallScript MSI Project

With InstallScript, you can use the RegDBGetKeyValueEx function. For example, to read the RegisteredOwner value from the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion, you can use code similar to the following:

function readRegisteredOwner( )

    STRING svRegisteredOwner;

    NUMBER nvType, nvSize;

begin

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);

 

RegDBGetKeyValueEx(

    "Software\\Microsoft\\Windows NT\\CurrentVersion",

    "RegisteredOwner",

    nvType,

    svRegisteredOwner,

    nvSize);

 

MessageBox(

    "Registered owner is: " + svRegisteredOwner,

    INFORMATION);

end;

You can set a Windows Installer property equal to the value you read using the MsiSetProperty function.

See Also