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.

149 lines
3.9 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. #include "stdpch.h"
  3. #include "..\common\WbemVersion.h"
  4. #include "..\common\Util.h"
  5. //----------------------------------------------------------------------
  6. LONG GetCimomFileName(LPTSTR filename, UINT size)
  7. {
  8. HKEY hkeyLocalMachine;
  9. LONG lResult;
  10. lResult = RegConnectRegistry(NULL, HKEY_LOCAL_MACHINE,
  11. &hkeyLocalMachine);
  12. if(lResult != ERROR_SUCCESS)
  13. {
  14. return lResult;
  15. }
  16. HKEY hkeyHmomCwd;
  17. lResult = RegOpenKeyEx(hkeyLocalMachine,
  18. _T("SOFTWARE\\Microsoft\\WBEM\\CIMOM"),
  19. 0,
  20. KEY_READ | KEY_QUERY_VALUE,
  21. &hkeyHmomCwd);
  22. if(lResult != ERROR_SUCCESS)
  23. {
  24. RegCloseKey(hkeyLocalMachine);
  25. return lResult;
  26. }
  27. TCHAR buf[MAX_PATH];
  28. unsigned long lcbValue = MAX_PATH * sizeof(TCHAR);
  29. unsigned long lType;
  30. lResult = RegQueryValueEx(hkeyHmomCwd,
  31. _T("Working Directory"),
  32. NULL, &lType,
  33. buf, &lcbValue);
  34. RegCloseKey(hkeyHmomCwd);
  35. RegCloseKey(hkeyLocalMachine);
  36. TCHAR cimomName[20] = {0};
  37. wcscpy(cimomName, _T("\\cimom.exe"));
  38. if((lResult == ERROR_SUCCESS) &&
  39. ((lcbValue + sizeof(cimomName)) <= size))
  40. {
  41. wcsncpy(filename, buf, MAX_PATH - wcslen(cimomName) - 1);
  42. wcsncat(filename, cimomName, wcslen(cimomName));
  43. }
  44. return lResult;
  45. }
  46. //----------------------------------------------------------------------
  47. bstr_t GetDoubleVersion(void)
  48. {
  49. // <myversion/cimomVer>
  50. TCHAR filename[MAX_PATH+1] = {0};
  51. GetModuleFileName(HINST_THISDLL, filename, MAX_PATH);
  52. bstr_t DoubleVersion = GetStringFileInfo(filename, _T("FileVersion"));
  53. // append cimom's version.
  54. DoubleVersion += _T("\\");
  55. DoubleVersion += GetCimomVersion();
  56. return DoubleVersion;
  57. }
  58. //----------------------------------------------------------------------
  59. bstr_t GetMyVersion(void)
  60. {
  61. TCHAR filename[MAX_PATH+1] = {0};
  62. GetModuleFileName(HINST_THISDLL, filename, MAX_PATH);
  63. return GetStringFileInfo(filename, _T("FileVersion"));
  64. }
  65. //----------------------------------------------------------------------
  66. bstr_t GetMyCompany(void)
  67. {
  68. TCHAR filename[MAX_PATH+1] = {0};
  69. GetModuleFileName(HINST_THISDLL, filename, MAX_PATH);
  70. return GetStringFileInfo(filename, _T("CompanyName"));
  71. }
  72. //----------------------------------------------------------------------
  73. bstr_t GetCimomVersion(void)
  74. {
  75. TCHAR filename[MAX_PATH+1] = {0};
  76. //if the wbem key, etc is there...
  77. if(GetCimomFileName(filename, sizeof(filename)) == ERROR_SUCCESS)
  78. {
  79. return GetStringFileInfo(filename, _T("FileVersion"));
  80. }
  81. return "No CIMOM";
  82. }
  83. //----------------------------------------------------------------------
  84. bstr_t GetStringFileInfo(LPCTSTR filename, LPCTSTR key)
  85. {
  86. _bstr_t sDesc("Unknown");
  87. DWORD infoSize = 0;
  88. UINT valSize = 0;
  89. LPBYTE info = NULL;
  90. DWORD handle = 0;
  91. LPVOID verStr = NULL;
  92. DWORD *TransBlk = NULL;
  93. TCHAR blockStr[100] = {0};
  94. infoSize = GetFileVersionInfoSize((LPTSTR)filename, &handle);
  95. if(infoSize)
  96. {
  97. info = new BYTE[infoSize];
  98. if(GetFileVersionInfo((LPTSTR)filename, handle,
  99. infoSize, info))
  100. {
  101. // get the translation block.
  102. // NOTE: This assumes that the localizers REPLACE the english with
  103. // the 'other' language so there will only be ONE entry in the
  104. // translation table. If we ever do a single binary that supports
  105. // multiple languages, it's a whole nother ballgame folks.
  106. if(VerQueryValue(info, _T("\\VarFileInfo\\Translation"),
  107. (void **)&TransBlk, &valSize))
  108. {
  109. snwprintf(blockStr, 100, _T("\\StringFileInfo\\%04hX%04hX\\%s"),
  110. LOWORD(*TransBlk),
  111. HIWORD(*TransBlk),
  112. key);
  113. if(VerQueryValue(info, (LPTSTR)blockStr,
  114. (void **)&verStr, &valSize))
  115. {
  116. sDesc = (TCHAR *)verStr;
  117. } //endif VerQueryValue()
  118. }
  119. } //endif GetFileVersionInfo()
  120. delete[] (LPBYTE)info;
  121. } // endif infoSize
  122. return sDesc;
  123. }