home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Demo / PCDUO / data1.cab / Script_Samples / GTCTLDIR.SCP < prev    next >
Encoding:
Text File  |  2003-11-28  |  4.4 KB  |  121 lines

  1. // GTCTLDIR.SCP - Sample Script function to return the Control's install directory
  2. // Copyright (c) 2000-2003, Vector Networks Limited
  3. // All Rights Reserved
  4. //
  5. // Revision History:
  6. //  5.3 19-Jul-00 AB  - Created.
  7. //      25-Jul-00 DB  - Add code to handle "quoted paths"
  8. //  7.0 09-Jan-02 DB  - Fix arithmetic broken by code changes
  9. //  8.1 20-Aug-03 DB  - Look for an InstallLocation= string.
  10. //                    - Enumerate uninstall keys if the Product Name 
  11. //                      Key is not found.
  12.  
  13. //  GetControlDir () uses the product-specific uninstall Key in 
  14. //  the Registry to find the Control's install directory.
  15. //
  16. //  This function requires:
  17. //  ProductName () - returns the product name string (e.g. "PC-Duo")
  18.  
  19. // If the Script that will use this function does not already INCLUDE PARSE,
  20. // uncomment the following line.
  21.  
  22. // $INCLUDE "PARSE.SCP"
  23. $INCLUDE "PRODNAME.SCP"
  24.  
  25. Function GetControlDir () as String
  26.     Dim ProdName as String, RegRoot, RootKey, RegName, RegKey
  27.     Dim PStrng as String, RStrng as String, Result as String, Status
  28.     Dim DType as Integer, KeyNames as List, KeyName as String
  29.  
  30.     //  Initialise an error result
  31.  
  32.     Result = ""
  33.  
  34.     //  Find our product name. This is variable.
  35.  
  36.     ProdName = ProductName ()
  37.  
  38.     //  Work out the uninstall Registry Key name and open it
  39.     //  This will not work unless InstallShield 5 was used. 
  40.  
  41.     RegRoot  = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 
  42.     RegName = RegRoot + "\" + ProdName
  43.     RegKey = RegOpenKey (HKEY_LOCAL_MACHINE, RegName)
  44.     
  45.     If RegKey then
  46.         RStrng = RegGetValue (RegKey, "InstallLocation", DType)
  47.  
  48.         If (DType = REG_SZ) AND IsString (RStrng) then
  49.             Result  = RStrng
  50.         Else
  51.             Print "ERROR: Unable to open the required registry value:"
  52.             Print RegName, "\", "InstallLocation"
  53.         Endif
  54.  
  55.         RegCloseKey (RegKey)
  56.     Else
  57.  
  58.         //  Installers after IS5 use a {GUID} uninstall root key. 
  59.         //  Enumerate the uninstall keys and work through them.
  60.         //  Open the Uninstall Root Ket first.
  61.  
  62.         RootKey = RegOpenKey (HKEY_LOCAL_MACHINE, RegRoot)
  63.  
  64.         If RootKey then
  65. //          Print "Uninstall Root Key <", RegRoot, "> opened."
  66.             If RegEnumKeys (RootKey, KeyNames) then
  67. //              Print "Searching for Product <", ProdName, ">"
  68.                 For Each KeyName in KeyNames
  69.                     RegName = RegRoot + "\" + KeyName
  70. //                  Print "Testing Key <", RegName, ">"
  71.  
  72.                     RegKey = RegOpenKey (HKEY_LOCAL_MACHINE, RegName)
  73.                     If RegKey then
  74. //                      Print "    Key <", KeyName, "> opened."
  75.  
  76.                         //  For each Key, check our Product Name against the 
  77.                         //  DisplayName, if there is one. If it matches, look for 
  78.                         //  the InstallLocation string. That's our answer.
  79.  
  80.                         PStrng = RegGetValue (RegKey, "DisplayName", DType)
  81.  
  82.                         If (DType = REG_SZ) AND IsString (PStrng) then
  83. //                          Print "    DisplayName <", PStrng, ">"
  84.  
  85.                             If Compare (PStrng, ProdName) = 0 then
  86. //                              Print "    Product <", ProdName, "> Key found."
  87.                                 RStrng = RegGetValue (RegKey, "InstallLocation", DType)
  88.  
  89.                                 If (DType = REG_SZ) AND IsString (RStrng) then
  90.                                     Result  = RStrng
  91. //                                  Print "    InstallLocation <", RStrng, "> found."
  92.                                     RegCloseKey (RegKey)
  93.                                     Exit For
  94.                                 Endif
  95.                             Endif
  96.                         Endif
  97.                         RegCloseKey (RegKey)
  98. //                      Print "    Key <", KeyName, "> closed."
  99.                     Endif
  100.                 Next
  101.             Endif
  102.  
  103.             RegCloseKey (RootKey)
  104. //          Print "Uninstall Root Key <", RegRoot, "> closed."
  105.         Else
  106.             Print "ERROR: Unable to open the required registry value:"
  107.             Print RegName, "\", "InstallLocation"
  108.         Endif
  109.     EndIf
  110.  
  111.     //  Return the result
  112.  
  113.     If Result != "" then
  114.         Print "Control Directory: ", Result
  115.     Else
  116.         Print "Control Directory not found!"
  117.     Endif
  118.  
  119.     GetControlDir = Result 
  120. End Function
  121.