Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Searching for a registry KEY (not value)


7 replies to this topic

Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 15 February 2001 - 20:00

I'd like to condition the installation of a component on the existance of a certain registry key. I don't care whether there's a entry (value) stored in the key. Using AppSearch/RegLocator will look for a certain registry entry. How can I distinguish between an a with no value, and a not existing key? Does the (Default) value always exist if the key exists? (In this case I could look for the default value).

Thanks in advance...


Art McKendry

Art McKendry
  • Members
  • 9 posts

Posted 15 February 2001 - 23:49

If you aren't adverse to script then you can use RegDBKeyExist (szSubKey);  it does not care if there are any values under it.  Only that the key exists.  This is kind of like lookig for a folder instead of a file in a folder...

Just add a custom action that calls this script and sets a property to TRUE/FALSE
export prototype MyKeyExists(HWND);

function MyKeyExists(hMsi)
STRINsRegKey;
LONGlResult;
begin
sRegKey="Software\\Widgets\\MyWidget";
RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
if (RegDBKeyExist(sRegKey) = 1) then
lResult=MsiSetProperty(hMsi,"REGKEYEXISTS",TRUE);
else
lResult=MsiSetProperty(hMsi,"REGKEYEXISTS",FALSE);
   endif;
return ERROR_SUCCESS;
end;

Remember to define REGKEYEXISTS in the properties editor of the project.


SteveP

SteveP
  • Members
  • 126 posts

Posted 16 February 2001 - 02:09

Another approach is to use the RegRead method under the Microsoft Windows Script Host.  The syntax is object.RegRead(strName) where the object is a WshShell object.  strName is the name of the key you want to read.  If the last character of the string is a backslash, the return is the key rather than the value.  If the Key does not exist an error is raised by the script host.  You can trap the error and set the return for your custom action to FALSE.

The following VB code snippet illustrates the process:

On Error Resume Next

Dim oObject As IWshShell
Dim sString As String

Set oObject = New IWshShell_Class
sString = oObject.RegRead("HKLM\SOFTWARE\SHS\Setup\Foobar\")

If Err.Number <> 0 Then MsgBox "error " & Str(Err.Number): End


Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 16 February 2001 - 07:16

Thanks you, Art and Steve. I was hoping for a "pure" Windows Installer solution, without custom action. Unfortunately this seems to be impossible.

rflum

rflum
  • Full Members
  • 40 posts

Posted 28 February 2001 - 22:10

Hi, Stefan,
 Well, not that I've seen every registry in the world, but I've never seen a key that didn't have a Default entry.
I'll bet looking for that would work.
 Rob

SteveP

SteveP
  • Members
  • 126 posts

Posted 01 March 2001 - 01:49

One issue with regard to the original post seems to be getting lost in the tall grass here.  If the registry entry is not tied to a file or directory signature, then using the RegLocator Table is not appropriate for accessing the key.  The use of the RegLocator Table is only initiated by the AppSearch Action.  Stefan's original question was with regard to confirming that a registry key exists, and no stipulation was made that the key is tied to any given file or folder.

The action of the AppSearch action is to set the Property indicated by the AppSearch Table to the value of the Signature.  If the Default Value is chosen, it is also often blank, and the Property Table does not allow blanks in the setting of a property name ... so I suspect the action would fail, even if the key existed.

I think the only way to guarantee the significance of the response would be to use a script object.  However, I have not tried using a dummy file/folder and looking for a key that is guaranteed to have some value associated with it, if it exists.


Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 01 March 2001 - 07:42

Steve,

thanks for your ideas. However I can search for registry entries that are not related to files in the AppSearch action. To do this I specify msidbLocatorTypeRawValue in the Type column. This works fine.
If the entry doesn't exist or is empty, the specified property will not exist (it's not specified in the property table) or will resolve to an empty string.

The problems are: Often a default value does not exist, even if the key exists. And if the default value exists, it may be empty, which I cannot destinguish (undefined property resolves to empty string). So a custom action (script or DLL) would be required to check for the existance of a key.

I worked around this limitation by looking for a value in the key that must not be empty.


mdelpin

mdelpin
  • Members
  • 4 posts

Posted 23 July 2001 - 21:42

I ran into a similar problem and just used the WI Installer.RegistryValue method.

object.RegistryValue(root, key, value)

If you do not specify a value it will return a boolean designating whether the key exists.

-maria