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

  1. // WINDOWS.SCP - Sample Script function to return the Control's Windows directory
  2. // Copyright (c) 2000, Vector Networks Limited
  3. // All Rights Reserved
  4. //
  5. // Revision History:
  6. //  6.0 01-Nov-00 DB  - Created, using GTCTLDIR.SCP
  7.  
  8. // GetWindowsDir returns the path to the Windows directory by looking
  9. // up the SystemRoot value in the Registry. This is stored under
  10. // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion on NT 
  11. // and HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion on 9x
  12.  
  13. Function GetWindowsDir () as String
  14.     Dim RegName, RegKey, RegValue, Result
  15.     Dim DType as Integer
  16.  
  17.     //  Initialise an error result
  18.  
  19.     Result = ""
  20.  
  21.     //  Work out the Registry Key name and open it
  22.     //  This is different for Windows 9x and NT. Try NT first...
  23.  
  24.     RegName = "SOFTWARE\Microsoft\Windows NT\CurrentVersion" 
  25.     RegKey = RegOpenKey (HKEY_LOCAL_MACHINE, RegName)
  26.     
  27.     If RegKey then
  28.         RegValue = RegGetValue (RegKey, "SystemRoot", DType)
  29.         RegCloseKey (RegKey)
  30.  
  31.         If (DType = REG_SZ) AND IsString (RegValue) then
  32.             Result = RegValue
  33.         Else
  34. //         Print "Unable to obtain Registry Value:"
  35. //         Print RegName, "\", "SystemRoot=", RegValue, ", Type=", DType
  36.         Endif
  37.     Endif
  38.  
  39.     If Result = "" Then
  40.  
  41.         // Maybe we are running on 9x. Try that next...
  42.  
  43.         RegName = "SOFTWARE\Microsoft\Windows\CurrentVersion" 
  44.         RegKey = RegOpenKey (HKEY_LOCAL_MACHINE, RegName)
  45.     
  46.         If RegKey then
  47.             RegValue = RegGetValue (RegKey, "SystemRoot", DType)
  48.             RegCloseKey (RegKey)
  49.  
  50.             If (DType = REG_SZ) AND IsString (RegValue) then
  51.                 Result = RegValue
  52.             Else
  53. //             Print "Unable to open the required registry value:"
  54. //             Print RegName, "\SystemRoot=", RegValue
  55.             Endif
  56.         EndIf
  57.     EndIf
  58.  
  59.     If Result = "" Then
  60.         Print "Unable to open required Registry Key:"
  61.         Print RegName, "\SystemRoot=", RegValue
  62.     Endif
  63.  
  64.     //  Return the result
  65.  
  66.     GetWindowsDir = Result 
  67. End Function
  68.  
  69. // GetWinSysDir returns the path to the Windows System directory using
  70. // the same mechanism as GetWindowsDir, above. It can tell by the result
  71. // whether it is running on Windows NT or 9x.
  72.  
  73. Function GetWinSysDir () as String
  74.     Dim RegName, RegKey, RegValue, Result
  75.     Dim DType as Integer
  76.  
  77.     //  Initialise an error result
  78.  
  79.     Result = ""
  80.  
  81.     //  Work out the Registry Key name and open it
  82.     //  This is different for Windows 9x and NT. Try NT first...
  83.  
  84.     RegName = "SOFTWARE\Microsoft\Windows NT\CurrentVersion" 
  85.     RegKey = RegOpenKey (HKEY_LOCAL_MACHINE, RegName)
  86.     
  87.     If RegKey then
  88.         RegValue = RegGetValue (RegKey, "SystemRoot", DType)
  89.         RegCloseKey (RegKey)
  90.  
  91.         If (DType = REG_SZ) AND IsString (RegValue) then
  92.             Result = RegValue + "\SYSTEM32"
  93.         Else
  94. //         Print "Unable to obtain Registry Value:"
  95. //         Print RegName, "\", "SystemRoot=", RegValue, ", Type=", DType
  96.         Endif
  97.     Endif
  98.  
  99.     If Result = "" Then
  100.  
  101.         // Maybe we are running on 9x. Try that next...
  102.  
  103.         RegName = "SOFTWARE\Microsoft\Windows\CurrentVersion" 
  104.         RegKey = RegOpenKey (HKEY_LOCAL_MACHINE, RegName)
  105.     
  106.         If RegKey then
  107.             RegValue = RegGetValue (RegKey, "SystemRoot", DType)
  108.             RegCloseKey (RegKey)
  109.  
  110.             If (DType = REG_SZ) AND IsString (RegValue) then
  111.                 Result = RegValue + "\SYSTEM"
  112.             Else
  113. //             Print "Unable to open the required registry value:"
  114. //             Print RegName, "\SystemRoot=", RegValue
  115.             Endif
  116.         EndIf
  117.     EndIf
  118.  
  119.     If Result = "" Then
  120.         Print "Unable to open required Registry Key:"
  121.         Print RegName, "\SystemRoot=", RegValue
  122.     Endif
  123.  
  124.     //  Return the result
  125.  
  126.     GetWinSysDir = Result 
  127. End Function
  128.