home *** CD-ROM | disk | FTP | other *** search
- // GTCTLDIR.SCP - Sample Script function to return the Control's install directory
- // Copyright (c) 2000-2003, Vector Networks Limited
- // All Rights Reserved
- //
- // Revision History:
- // 5.3 19-Jul-00 AB - Created.
- // 25-Jul-00 DB - Add code to handle "quoted paths"
- // 7.0 09-Jan-02 DB - Fix arithmetic broken by code changes
- // 8.1 20-Aug-03 DB - Look for an InstallLocation= string.
- // - Enumerate uninstall keys if the Product Name
- // Key is not found.
-
- // GetControlDir () uses the product-specific uninstall Key in
- // the Registry to find the Control's install directory.
- //
- // This function requires:
- // ProductName () - returns the product name string (e.g. "PC-Duo")
-
- // If the Script that will use this function does not already INCLUDE PARSE,
- // uncomment the following line.
-
- // $INCLUDE "PARSE.SCP"
- $INCLUDE "PRODNAME.SCP"
-
- Function GetControlDir () as String
- Dim ProdName as String, RegRoot, RootKey, RegName, RegKey
- Dim PStrng as String, RStrng as String, Result as String, Status
- Dim DType as Integer, KeyNames as List, KeyName as String
-
- // Initialise an error result
-
- Result = ""
-
- // Find our product name. This is variable.
-
- ProdName = ProductName ()
-
- // Work out the uninstall Registry Key name and open it
- // This will not work unless InstallShield 5 was used.
-
- RegRoot = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
- RegName = RegRoot + "\" + ProdName
- RegKey = RegOpenKey (HKEY_LOCAL_MACHINE, RegName)
-
- If RegKey then
- RStrng = RegGetValue (RegKey, "InstallLocation", DType)
-
- If (DType = REG_SZ) AND IsString (RStrng) then
- Result = RStrng
- Else
- Print "ERROR: Unable to open the required registry value:"
- Print RegName, "\", "InstallLocation"
- Endif
-
- RegCloseKey (RegKey)
- Else
-
- // Installers after IS5 use a {GUID} uninstall root key.
- // Enumerate the uninstall keys and work through them.
- // Open the Uninstall Root Ket first.
-
- RootKey = RegOpenKey (HKEY_LOCAL_MACHINE, RegRoot)
-
- If RootKey then
- // Print "Uninstall Root Key <", RegRoot, "> opened."
- If RegEnumKeys (RootKey, KeyNames) then
- // Print "Searching for Product <", ProdName, ">"
- For Each KeyName in KeyNames
- RegName = RegRoot + "\" + KeyName
- // Print "Testing Key <", RegName, ">"
-
- RegKey = RegOpenKey (HKEY_LOCAL_MACHINE, RegName)
- If RegKey then
- // Print " Key <", KeyName, "> opened."
-
- // For each Key, check our Product Name against the
- // DisplayName, if there is one. If it matches, look for
- // the InstallLocation string. That's our answer.
-
- PStrng = RegGetValue (RegKey, "DisplayName", DType)
-
- If (DType = REG_SZ) AND IsString (PStrng) then
- // Print " DisplayName <", PStrng, ">"
-
- If Compare (PStrng, ProdName) = 0 then
- // Print " Product <", ProdName, "> Key found."
- RStrng = RegGetValue (RegKey, "InstallLocation", DType)
-
- If (DType = REG_SZ) AND IsString (RStrng) then
- Result = RStrng
- // Print " InstallLocation <", RStrng, "> found."
- RegCloseKey (RegKey)
- Exit For
- Endif
- Endif
- Endif
- RegCloseKey (RegKey)
- // Print " Key <", KeyName, "> closed."
- Endif
- Next
- Endif
-
- RegCloseKey (RootKey)
- // Print "Uninstall Root Key <", RegRoot, "> closed."
- Else
- Print "ERROR: Unable to open the required registry value:"
- Print RegName, "\", "InstallLocation"
- Endif
- EndIf
-
- // Return the result
-
- If Result != "" then
- Print "Control Directory: ", Result
- Else
- Print "Control Directory not found!"
- Endif
-
- GetControlDir = Result
- End Function
-