Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
6.2 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // InstallState.cpp
  7. //
  8. // Desription:
  9. // The function(s) in this file are used to interrogate the state of the
  10. // Clustering Services installation.
  11. //
  12. // Author:
  13. // C. Brent Thomas (a-brentt) 6 May 1998
  14. //
  15. // Revision History:
  16. //
  17. // Notes:
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include <clusrtlp.h>
  21. #include <stdlib.h>
  22. #include "clusrtl.h"
  23. /////////////////////////////////////////////////////////////////////////////
  24. //++
  25. //
  26. // ClRtlGetClusterInstallState
  27. //
  28. // Routine Description:
  29. // This function retrieves an indicator of the state of the Cluster Server
  30. // installation.
  31. //
  32. // Arguments:
  33. // pszNodeName - Name of the node to check, or NULL for the local machine.
  34. // peState - State value returned from this function:
  35. // eClusterInstallStateUnknown - indicates that the state of the Cluster
  36. // Server installation could not be determined.
  37. // eClusterInstallStateFilesCopied - indicates that clusocm.dll has prevoiusly,
  38. // successfully copied the Cluster Server files.
  39. // eClusterInstallStateConfigured - indicates that the Cluster Server has previously
  40. // been configured successfully.
  41. // See cluster\inc\clusrtl.h for the definition of eClusterInstallState.
  42. //
  43. // Return Value:
  44. // Any error codes returned from RegConnectRegistryW, RegOpenKeyExW, or RegQueryValueExW.
  45. //
  46. //--
  47. /////////////////////////////////////////////////////////////////////////////
  48. DWORD ClRtlGetClusterInstallState(
  49. IN LPCWSTR pszNodeName,
  50. OUT eClusterInstallState * peState
  51. )
  52. {
  53. HKEY hKey = NULL;
  54. HKEY hParentKey = HKEY_LOCAL_MACHINE;
  55. DWORD dwStatus; // returned by registry API functions
  56. DWORD dwClusterInstallState;
  57. DWORD dwValueType;
  58. DWORD dwDataBufferSize = sizeof( DWORD );
  59. *peState = eClusterInstallStateUnknown;
  60. // Connect to a remote computer if specified.
  61. if ( pszNodeName != NULL )
  62. {
  63. dwStatus = RegConnectRegistryW( pszNodeName, HKEY_LOCAL_MACHINE, &hParentKey );
  64. if ( dwStatus != ERROR_SUCCESS )
  65. {
  66. goto FnExit;
  67. } // if: error connecting to remote registry
  68. } // if: node name specified
  69. // Read the registry key that indicates whether cluster files are installed.
  70. dwStatus = RegOpenKeyExW( hParentKey,
  71. L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Cluster Server",
  72. 0, // reserved
  73. KEY_READ,
  74. &hKey );
  75. // Was the registry key opened successfully ?
  76. if ( dwStatus != ERROR_SUCCESS )
  77. {
  78. if ( dwStatus == ERROR_FILE_NOT_FOUND )
  79. {
  80. dwStatus = ERROR_SUCCESS;
  81. }
  82. goto FnExit;
  83. }
  84. // Read the entry.
  85. dwStatus = RegQueryValueExW( hKey,
  86. L"ClusterInstallationState",
  87. 0, // reserved
  88. &dwValueType,
  89. (LPBYTE) &dwClusterInstallState,
  90. &dwDataBufferSize );
  91. // Was the value read successfully ?
  92. if ( dwStatus != ERROR_SUCCESS )
  93. {
  94. if ( dwStatus == ERROR_FILE_NOT_FOUND )
  95. {
  96. dwStatus = ERROR_SUCCESS;
  97. }
  98. goto FnExit;
  99. }
  100. if ( dwValueType == REG_DWORD )
  101. {
  102. *peState = (eClusterInstallState) dwClusterInstallState;
  103. }
  104. FnExit:
  105. // Close the registry key.
  106. if ( hKey )
  107. {
  108. RegCloseKey( hKey );
  109. }
  110. if ( hParentKey != HKEY_LOCAL_MACHINE )
  111. {
  112. RegCloseKey( hParentKey );
  113. }
  114. return ( dwStatus );
  115. } //*** ClRtlGetClusterInstallState()
  116. /////////////////////////////////////////////////////////////////////////////
  117. //++
  118. //
  119. // ClRtlSetClusterInstallState
  120. //
  121. // Routine Description:
  122. // This function sets the registry value that records the state of the
  123. // Clustering Service installation.
  124. //
  125. // Arguments:
  126. // hInstance - The handle to the application instance - necessary for the calls
  127. // to LoadString.
  128. //
  129. // eInstallState - the state to which the registry value should be set.
  130. //
  131. // Return Value:
  132. // TRUE - indicates that the registry value was set successfully
  133. // FALSE - indicates that some error occured.
  134. //
  135. //--
  136. /////////////////////////////////////////////////////////////////////////////
  137. BOOL ClRtlSetClusterInstallState( eClusterInstallState eInstallState )
  138. {
  139. //initialize return to FALSE
  140. BOOL fReturnValue = FALSE;
  141. // Set the state of the ClusterInstallationState registry key to indicate
  142. // that Cluster Server has been configured.
  143. HKEY hKey;
  144. DWORD dwStatus; // returned by registry API functions
  145. // Attempt to open an existing key in the registry.
  146. dwStatus = RegOpenKeyExW( HKEY_LOCAL_MACHINE,
  147. L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Cluster Server",
  148. 0, // reserved
  149. KEY_WRITE,
  150. &hKey );
  151. // Was the regustry key opened successfully ?
  152. if ( dwStatus == ERROR_SUCCESS )
  153. {
  154. // Update the value.
  155. DWORD dwClusterInstallState = eInstallState;
  156. DWORD dwValueType = REG_DWORD;
  157. DWORD dwDataBufferSize = sizeof( DWORD );
  158. dwStatus = RegSetValueExW( hKey,
  159. L"ClusterInstallationState",
  160. 0, // reserved
  161. dwValueType,
  162. (LPBYTE) &dwClusterInstallState,
  163. dwDataBufferSize );
  164. // Close the registry key.
  165. RegCloseKey( hKey );
  166. // Was the value set successfully?
  167. if ( dwStatus == ERROR_SUCCESS )
  168. {
  169. fReturnValue = TRUE;
  170. }
  171. }
  172. return ( fReturnValue );
  173. } //*** ClRtlSetClusterInstallState()