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.

274 lines
8.5 KiB

  1. //++
  2. //
  3. // Copyright (C) Microsoft Corporation, 1987 - 1999
  4. //
  5. // Module Name:
  6. //
  7. // machine.c
  8. //
  9. // Abstract:
  10. //
  11. // Test to ensure that a workstation has network (IP) connectivity to
  12. // the outside.
  13. //
  14. // Author:
  15. //
  16. // 15-Dec-1997 (cliffv)
  17. // Anilth - 4-20-1998
  18. //
  19. // Environment:
  20. //
  21. // User mode only.
  22. // Contains NT-specific code.
  23. //
  24. // Revision History:
  25. //
  26. //--
  27. //
  28. // Common include files.
  29. //
  30. #include "precomp.h"
  31. #include "strings.h"
  32. HRESULT GetHotfixInfo(NETDIAG_RESULT *pResults, HKEY hkeyLocalMachine);
  33. /*!--------------------------------------------------------------------------
  34. GetMachineSpecificInfo
  35. Get the OS info for the specified machine.
  36. Author: KennT
  37. ---------------------------------------------------------------------------*/
  38. HRESULT GetMachineSpecificInfo(IN NETDIAG_PARAMS *pParams,
  39. IN OUT NETDIAG_RESULT *pResults)
  40. {
  41. HKEY hkey = HKEY_LOCAL_MACHINE;
  42. HKEY hkeyBuildNumber = NULL;
  43. HKEY hkeyNTType;
  44. DWORD dwErr;
  45. DWORD dwType, dwLen;
  46. DWORD dwMaxLen = 0;
  47. HRESULT hr = hrOK;
  48. TCHAR szBuffer[256];
  49. CheckErr( RegOpenKeyEx( hkey,
  50. c_szRegKeyWindowsNTCurrentVersion,
  51. 0,
  52. KEY_READ,
  53. &hkeyBuildNumber) );
  54. RegQueryInfoKey(hkeyBuildNumber,
  55. NULL, // lpclass
  56. NULL, // lpcbClass
  57. NULL, // lpReserved
  58. NULL, // lpcSubkeys
  59. NULL, // lpcbMaxSubkeyLen
  60. NULL, // lpcbMaxClassLen
  61. NULL, // lpcValues
  62. NULL, // lpcbMaxValueNameLen
  63. &dwMaxLen, // lpcbMaxValueLen
  64. NULL, // lpSecurity
  65. NULL); // last write time
  66. pResults->Global.pszCurrentVersion = Malloc((dwMaxLen+1) * sizeof(TCHAR));
  67. if (pResults->Global.pszCurrentVersion == NULL)
  68. CheckHr( E_OUTOFMEMORY );
  69. pResults->Global.pszCurrentBuildNumber = Malloc((dwMaxLen+1) * sizeof(TCHAR));
  70. if (pResults->Global.pszCurrentBuildNumber == NULL)
  71. CheckHr( E_OUTOFMEMORY );
  72. pResults->Global.pszCurrentType = Malloc((dwMaxLen+1) * sizeof(TCHAR));
  73. if (pResults->Global.pszCurrentType == NULL)
  74. CheckHr( E_OUTOFMEMORY );
  75. dwLen = dwMaxLen;
  76. CheckErr( RegQueryValueEx(hkeyBuildNumber,
  77. c_szRegCurrentType,
  78. (LPDWORD) NULL,
  79. &dwType,
  80. (LPBYTE) pResults->Global.pszCurrentType,
  81. &dwLen) );
  82. dwLen = dwMaxLen;
  83. CheckErr( RegQueryValueEx(hkeyBuildNumber,
  84. c_szRegCurrentVersion,
  85. (LPDWORD) NULL,
  86. &dwType,
  87. (LPBYTE) pResults->Global.pszCurrentVersion,
  88. &dwLen) );
  89. dwLen = dwMaxLen;
  90. dwErr = RegQueryValueEx( hkeyBuildNumber,
  91. c_szRegCurrentBuildNumber,
  92. (LPDWORD) NULL,
  93. &dwType,
  94. (LPBYTE) pResults->Global.pszCurrentBuildNumber,
  95. &dwLen);
  96. if (dwErr != ERROR_SUCCESS) {
  97. dwLen = dwMaxLen;
  98. dwErr = RegQueryValueEx( hkeyBuildNumber,
  99. c_szRegCurrentBuild,
  100. (LPDWORD) NULL,
  101. &dwType,
  102. (LPBYTE) pResults->Global.pszCurrentBuildNumber,
  103. & dwLen);
  104. }
  105. GetEnvironmentVariable(_T("PROCESSOR_IDENTIFIER"),
  106. szBuffer,
  107. DimensionOf(szBuffer));
  108. pResults->Global.pszProcessorInfo = StrDup(szBuffer);
  109. CheckErr( RegOpenKeyEx( hkey,
  110. c_szRegKeyControlProductOptions,
  111. 0,
  112. KEY_READ,
  113. &hkeyNTType) );
  114. dwLen = DimensionOf(szBuffer);
  115. dwErr = RegQueryValueEx( hkeyNTType,
  116. _T("ProductType"),
  117. (LPDWORD) NULL,
  118. &dwType,
  119. (LPBYTE) szBuffer,
  120. & dwLen);
  121. if (dwErr == ERROR_SUCCESS)
  122. {
  123. if (StriCmp(szBuffer, _T("WinNT")) == 0)
  124. {
  125. pResults->Global.pszServerType = LoadAndAllocString(IDS_GLOBAL_PROFESSIONAL);
  126. }
  127. else
  128. {
  129. pResults->Global.pszServerType = LoadAndAllocString(IDS_GLOBAL_SERVER);
  130. }
  131. }
  132. // get the hotfix information
  133. GetHotfixInfo(pResults, hkey);
  134. hr = HResultFromWin32(dwErr);
  135. Error:
  136. if ( hkeyNTType != NULL )
  137. (VOID) RegCloseKey(hkeyNTType);
  138. if ( hkeyBuildNumber != NULL )
  139. (VOID) RegCloseKey(hkeyBuildNumber);
  140. if (FAILED(hr))
  141. {
  142. //IDS_GLOBAL_NO_MACHINE_INFO "[FATAL] Failed to get system information of this machine.\n"
  143. PrintMessage(pParams, IDS_GLOBAL_NO_MACHINE_INFO);
  144. }
  145. return hr;
  146. }
  147. /*!--------------------------------------------------------------------------
  148. GetHotfixInfo
  149. -
  150. Author: KennT
  151. ---------------------------------------------------------------------------*/
  152. HRESULT GetHotfixInfo(NETDIAG_RESULT *pResults, HKEY hkeyLocalMachine)
  153. {
  154. HRESULT hr = hrOK;
  155. HKEY hkeyHotFix = NULL;
  156. HKEY hkeyMainHotFix = NULL;
  157. TCHAR szBuffer[MAX_PATH];
  158. DWORD cchBuffer = MAX_PATH;
  159. DWORD i = 0;
  160. DWORD cSubKeys = 0;
  161. DWORD dwType, dwLen, dwInstalled;
  162. // Open the hotfix registry key
  163. CheckErr( RegOpenKeyEx( hkeyLocalMachine,
  164. c_szRegKeyHotFix,
  165. 0,
  166. KEY_READ,
  167. &hkeyMainHotFix) );
  168. // Get the list of summary information
  169. RegQueryInfoKey(hkeyMainHotFix,
  170. NULL, // lpclass
  171. NULL, // lpcbClass
  172. NULL, // lpReserved
  173. &cSubKeys, // lpcSubkeys
  174. NULL, // lpcbMaxSubkeyLen
  175. NULL, // lpcbMaxClassLen
  176. NULL, // lpcValues
  177. NULL, // lpcbMaxValueNameLen
  178. NULL, // lpcbMaxValueLen
  179. NULL, // lpSecurity
  180. NULL); // last write time
  181. assert(pResults->Global.pHotFixes == NULL);
  182. pResults->Global.pHotFixes = Malloc(sizeof(HotFixInfo)*cSubKeys);
  183. if (pResults->Global.pHotFixes == NULL)
  184. CheckHr(E_OUTOFMEMORY);
  185. ZeroMemory(pResults->Global.pHotFixes, sizeof(HotFixInfo)*cSubKeys);
  186. // Enumerate the keys under this to get the list of hotfixes
  187. while ( RegEnumKeyEx( hkeyMainHotFix,
  188. i,
  189. szBuffer,
  190. &cchBuffer,
  191. NULL,
  192. NULL,
  193. NULL,
  194. NULL) == ERROR_SUCCESS)
  195. {
  196. // Now add an entry for each key
  197. pResults->Global.pHotFixes[i].fInstalled = FALSE;
  198. pResults->Global.pHotFixes[i].pszName = StrDup(szBuffer);
  199. // Open up the key and get the installed value
  200. assert(hkeyHotFix == NULL);
  201. CheckErr( RegOpenKeyEx( hkeyMainHotFix,
  202. szBuffer,
  203. 0,
  204. KEY_READ,
  205. &hkeyHotFix) );
  206. // Now get the value
  207. dwType = REG_DWORD;
  208. dwInstalled = FALSE;
  209. dwLen = sizeof(DWORD);
  210. if (RegQueryValueEx(hkeyHotFix,
  211. c_szRegInstalled,
  212. (LPDWORD) NULL,
  213. &dwType,
  214. (LPBYTE) &dwInstalled,
  215. &dwLen) == ERROR_SUCCESS)
  216. {
  217. if (dwType == REG_DWORD)
  218. pResults->Global.pHotFixes[i].fInstalled = dwInstalled;
  219. }
  220. if (hkeyHotFix)
  221. RegCloseKey(hkeyHotFix);
  222. hkeyHotFix = NULL;
  223. i ++;
  224. pResults->Global.cHotFixes++;
  225. cchBuffer = MAX_PATH;
  226. }
  227. Error:
  228. if (hkeyHotFix)
  229. RegCloseKey(hkeyHotFix);
  230. if (hkeyMainHotFix)
  231. RegCloseKey(hkeyMainHotFix);
  232. return hr;
  233. }