Leaked source code of windows server 2003
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.

125 lines
3.6 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright Microsoft Corporation
  4. //
  5. // Module Name:
  6. //
  7. // aaaaVersion.cpp
  8. //
  9. // Abstract:
  10. //
  11. // Handlers for aaaa version command
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #include "stdafx.h"
  15. #include "strdefs.h"
  16. #include "aaaamon.h"
  17. #include "aaaaversion.h"
  18. //////////////////////////////////////////////////////////////////////////////
  19. // AaaaVersionGetVersion
  20. //////////////////////////////////////////////////////////////////////////////
  21. HRESULT AaaaVersionGetVersion(LONG* pVersion)
  22. {
  23. const int SIZE_MAX_STRING = 512;
  24. const WCHAR c_wcSELECT_VERSION[] = L"SELECT * FROM Version";
  25. const WCHAR c_wcIASMDBFileName[] = L"%SystemRoot%\\System32\\ias\\ias.mdb";
  26. if ( !pVersion )
  27. {
  28. return ERROR;
  29. }
  30. bool bCoInitialized = false;
  31. HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  32. if ( FAILED(hr) )
  33. {
  34. if ( hr == RPC_E_CHANGED_MODE )
  35. {
  36. hr = S_OK;
  37. }
  38. else
  39. {
  40. *pVersion = 0;
  41. return hr;
  42. }
  43. }
  44. else
  45. {
  46. bCoInitialized = true;
  47. }
  48. WCHAR wc_TempString[SIZE_MAX_STRING];
  49. // put the path to the DB in the property.
  50. BOOL bResult = ExpandEnvironmentStringsForUserW(
  51. NULL,
  52. c_wcIASMDBFileName,
  53. wc_TempString,
  54. SIZE_MAX_STRING
  55. );
  56. do
  57. {
  58. if ( bResult )
  59. {
  60. CComPtr<IIASNetshJetHelper> JetHelper;
  61. hr = CoCreateInstance(
  62. __uuidof(CIASNetshJetHelper),
  63. NULL,
  64. CLSCTX_SERVER,
  65. __uuidof(IIASNetshJetHelper),
  66. (PVOID*) &JetHelper
  67. );
  68. if ( FAILED(hr) )
  69. {
  70. break;
  71. }
  72. CComBSTR DBPath(wc_TempString);
  73. if ( !DBPath )
  74. {
  75. hr = E_OUTOFMEMORY;
  76. break;
  77. }
  78. hr = JetHelper->OpenJetDatabase(DBPath, FALSE);
  79. if ( FAILED(hr) )
  80. {
  81. WCHAR sDisplayString[SIZE_MAX_STRING];
  82. DisplayError(NULL, EMSG_OPEN_DB_FAILED);
  83. break;
  84. }
  85. CComBSTR SelectVersion(c_wcSELECT_VERSION);
  86. if ( !SelectVersion )
  87. {
  88. hr = E_OUTOFMEMORY;
  89. break;
  90. }
  91. hr = JetHelper->ExecuteSQLFunction(
  92. SelectVersion,
  93. pVersion
  94. );
  95. if ( FAILED(hr) ) // no Misc Table for instance
  96. {
  97. *pVersion = 0; //default value.
  98. hr = S_OK; // that's not an error
  99. }
  100. hr = JetHelper->CloseJetDatabase();
  101. }
  102. else
  103. {
  104. DisplayMessage(g_hModule, MSG_AAAAVERSION_GET_FAIL);
  105. hr = E_FAIL;
  106. break;
  107. }
  108. } while(false);
  109. if (bCoInitialized)
  110. {
  111. CoUninitialize();
  112. }
  113. return hr;
  114. }