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.

226 lines
6.5 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. //
  7. // aaaaVersion.cpp
  8. //
  9. // Abstract:
  10. //
  11. // Handlers for aaaa version command
  12. //
  13. // Revision History:
  14. //
  15. // pmay
  16. // tperraut 04/02/1999
  17. // tperraut 04/17/2000 Use the Jet wrapper from iasrecst.dll
  18. //
  19. //////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "strdefs.h"
  22. #include "aaaamon.h"
  23. #include "aaaaversion.h"
  24. const int SIZE_MAX_STRING = 512;
  25. //////////////////////////////////////////////////////////////////////////////
  26. // AaaaVersionGetVersion
  27. //////////////////////////////////////////////////////////////////////////////
  28. HRESULT AaaaVersionGetVersion(LONG* pVersion)
  29. {
  30. const WCHAR c_wcSELECT_VERSION[] = L"SELECT * FROM Version";
  31. const WCHAR c_wcIASMDBFileName[] = L"%SystemRoot%\\System32\\ias\\ias.mdb";
  32. if ( !pVersion )
  33. {
  34. return ERROR;
  35. }
  36. bool bCoInitialized = false;
  37. HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  38. if ( FAILED(hr) )
  39. {
  40. if ( hr == RPC_E_CHANGED_MODE )
  41. {
  42. hr = S_OK;
  43. }
  44. else
  45. {
  46. *pVersion = 0;
  47. return hr;
  48. }
  49. }
  50. else
  51. {
  52. bCoInitialized = true;
  53. }
  54. WCHAR wc_TempString[SIZE_MAX_STRING];
  55. // put the path to the DB in the property.
  56. BOOL bResult = ExpandEnvironmentStringsForUserW(
  57. NULL,
  58. c_wcIASMDBFileName,
  59. wc_TempString,
  60. SIZE_MAX_STRING
  61. );
  62. do
  63. {
  64. if ( bResult )
  65. {
  66. CComPtr<IIASNetshJetHelper> JetHelper;
  67. hr = CoCreateInstance(
  68. __uuidof(CIASNetshJetHelper),
  69. NULL,
  70. CLSCTX_SERVER,
  71. __uuidof(IIASNetshJetHelper),
  72. (PVOID*) &JetHelper
  73. );
  74. if ( FAILED(hr) )
  75. {
  76. break;
  77. }
  78. CComBSTR DBPath(wc_TempString);
  79. if ( !DBPath )
  80. {
  81. hr = E_OUTOFMEMORY;
  82. break;
  83. }
  84. hr = JetHelper->OpenJetDatabase(DBPath, FALSE);
  85. if ( FAILED(hr) )
  86. {
  87. WCHAR sDisplayString[SIZE_MAX_STRING];
  88. DisplayError(NULL, EMSG_OPEN_DB_FAILED);
  89. break;
  90. }
  91. CComBSTR SelectVersion(c_wcSELECT_VERSION);
  92. if ( !SelectVersion )
  93. {
  94. hr = E_OUTOFMEMORY;
  95. break;
  96. }
  97. hr = JetHelper->ExecuteSQLFunction(
  98. SelectVersion,
  99. pVersion
  100. );
  101. if ( FAILED(hr) ) // no Misc Table for instance
  102. {
  103. *pVersion = 0; //default value.
  104. hr = S_OK; // that's not an error
  105. }
  106. hr = JetHelper->CloseJetDatabase();
  107. }
  108. else
  109. {
  110. DisplayMessage(g_hModule, MSG_AAAAVERSION_GET_FAIL);
  111. hr = E_FAIL;
  112. break;
  113. }
  114. } while(false);
  115. if (bCoInitialized)
  116. {
  117. CoUninitialize();
  118. }
  119. return hr;
  120. }
  121. //////////////////////////////////////////////////////////////////////////////
  122. // AaaaVersionParseCommandLine
  123. //
  124. // Parses the AaaaVersion from the command line
  125. //////////////////////////////////////////////////////////////////////////////
  126. DWORD
  127. AaaaVersionParseCommandLine(
  128. IN PWCHAR* ppwcArguments,
  129. IN DWORD dwCurrentIndex,
  130. IN DWORD dwArgCount
  131. )
  132. {
  133. return NO_ERROR;
  134. }
  135. //////////////////////////////////////////////////////////////////////////////
  136. // AaaaVersionProcessCommand
  137. //
  138. // Processes a command by parsing the command line
  139. // and calling the appropriate callback
  140. //////////////////////////////////////////////////////////////////////////////
  141. DWORD
  142. AaaaVersionProcessCommand(
  143. IN PWCHAR* ppwcArguments,
  144. IN DWORD dwCurrentIndex,
  145. IN DWORD dwArgCount,
  146. IN BOOL* pbDone,
  147. IN HANDLE hData
  148. )
  149. {
  150. DWORD dwErr = NO_ERROR;
  151. if (dwCurrentIndex != dwArgCount)
  152. {
  153. // some arguments are present on the command line and will be ignored
  154. DisplayMessage(g_hModule, MSG_AAAAVERSION_SHOW_FAIL);
  155. }
  156. else
  157. {
  158. LONG lVersion;
  159. HRESULT hr = AaaaVersionGetVersion(&lVersion);
  160. if (!FAILED(hr))
  161. {
  162. WCHAR sDisplayString[SIZE_MAX_STRING];
  163. _snwprintf(
  164. sDisplayString,
  165. SIZE_MAX_STRING,
  166. L"Version = %d\n",
  167. lVersion
  168. );
  169. DisplayMessageT(sDisplayString);
  170. }
  171. else
  172. {
  173. DisplayMessage(g_hModule, MSG_AAAAVERSION_GET_FAIL);
  174. dwErr = ERROR;
  175. }
  176. }
  177. return dwErr;
  178. }
  179. //////////////////////////////////////////////////////////////////////////////
  180. // HandleAaaaVersionShow
  181. //
  182. // Shows whether HandleAaaaVersionSet has been called on the
  183. // given domain.
  184. //////////////////////////////////////////////////////////////////////////////
  185. DWORD
  186. HandleAaaaVersionShow(
  187. IN LPCWSTR pwszMachine,
  188. IN OUT LPWSTR *ppwcArguments,
  189. IN DWORD dwCurrentIndex,
  190. IN DWORD dwArgCount,
  191. IN DWORD dwFlags,
  192. IN LPCVOID pvData,
  193. OUT BOOL *pbDone
  194. )
  195. {
  196. return AaaaVersionProcessCommand(
  197. ppwcArguments,
  198. dwCurrentIndex,
  199. dwArgCount,
  200. pbDone,
  201. NULL
  202. );
  203. }