Задача: Утилиты
Исходник: Надежная проверка - установлен ли MS office, язык: C++ [code #550, hits: 7162]
автор: - [добавлен: 19.12.2007]
  1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include <conio.h>
  4. //#include <ostream.h>
  5. //#include <fstream>
  6.  
  7. #include <msi.h>
  8. #pragma comment(lib,"msi.lib")
  9.  
  10.  
  11.  
  12. class MsiProductsChecker
  13. {
  14. virtual void CheckProductID(GUID prodId) = 0;
  15. public:
  16. void DoCheck()
  17. {
  18. int i=0;
  19. WCHAR guid_str[255] = {0};
  20. while(ERROR_SUCCESS == MsiEnumProductsW(i++,guid_str))
  21. {
  22. GUID guid = {0};
  23. ::IIDFromString(guid_str,&guid);
  24. CheckProductID(guid);
  25. }
  26. }
  27. };
  28. class OfficeProductChecker : public MsiProductsChecker
  29. {
  30. virtual void CheckProductID(GUID prodId)
  31. {
  32. CheckOffice2000(prodId);
  33. CheckOfficeXP(prodId);
  34. CheckOffice2003(prodId);
  35. CheckOffice2007(prodId);
  36. }
  37. bool IsOffice2000_XP_2003_Family(GUID prodId, LPOLESTR patternStr)
  38. {
  39. GUID pattern;
  40. ::IIDFromString(patternStr,&pattern); //{xxyyzzzz-????-????-????-????????????}
  41. pattern.Data1 = prodId.Data1;
  42. return 0 != IsEqualGUID(pattern,prodId);
  43.  
  44. }
  45. void CheckOffice2000(GUID prodId)
  46. {
  47. if (!IsOffice2000_XP_2003_Family(prodId,L"{00000000-78E1-11D2-B60F-006097C998E7}"))
  48. return;
  49. //KB 230848
  50. //{xxyyzzzz-78E1-11D2-B60F-006097C998E7}
  51. //Characters Definition values
  52. // -------------------------------------------------------------
  53. // xx The version of the product 00-FF
  54. // yy The SKU of the product 00-FF
  55. // zzzz The language identifier of the product any required
  56.  
  57. long sku = (prodId.Data1 >> 16) & 0xFF;
  58. switch(sku)
  59. {
  60. case 0x00: //Microsoft Office 2000 Premium Edition CD1
  61. case 0x01: //Microsoft Office 2000 Professional Edition
  62. case 0x02: //Microsoft Office 2000 Standard Edition
  63. case 0x03: //Microsoft Office 2000 Small Business Edition
  64. case 0x04: //Microsoft Office 2000 Premium CD2
  65. case 0x05: //Office CD2 SMALL
  66. m_Office2000Installed = true;
  67. break;
  68. default:
  69. ;
  70. }
  71. }
  72. void CheckOfficeXP(GUID prodId)
  73. {
  74. if (!IsOffice2000_XP_2003_Family(prodId,L"{00000000-6000-11D3-8CFE-0050048383C9}"))
  75. return;
  76. //KB 302663
  77. //{WXYYZZZZ-6000-11D3-8CFE-0050048383C9}
  78. //Characters Definition Hex values
  79. // ------------------------------------------------------------------
  80. // W Release type 0-9, A-F
  81. // X Edition type 0-2
  82. // YY SKU of the product 10-35
  83. // ZZZZ Language identifier of the product any required
  84.  
  85. long release = (prodId.Data1 >> (8*3 + 4)) & 0xF;
  86. long sku = (prodId.Data1 >> 16) & 0xFF;
  87.  
  88. if (release < 9)
  89. return; //it's beta or RC
  90.  
  91. switch(sku)
  92. {
  93. case 0x11: //Microsoft Office XP Professional
  94. case 0x12: //Microsoft Office XP Standard
  95. case 0x13: //Microsoft Office XP Small Business
  96. case 0x28: //Microsoft Office XP Professional with FrontPage
  97. case 0x29: //Microsoft Office XP Professional Subscription
  98. case 0x2A: //Microsoft Office XP Small Business Edition Subscription
  99. case 0x33: //Microsoft Office XP PIPC1 (Pre Installed PC) (JPN Only)
  100. case 0x34: //Microsoft Office XP PIPC2 (Pre Installed PC) (JPN Only)
  101. m_OfficeXPInstalled = true;
  102. break;
  103. default:
  104. ;
  105. }
  106. }
  107. void CheckOffice2003(GUID prodId)
  108. {
  109. if (!IsOffice2000_XP_2003_Family(prodId,L"{00000000-6000-11D3-8CFE-0150048383C9}"))
  110. return;
  111. //KB 832672
  112. //{WXYYZZZZ-6000-11D3-8CFE-0150048383C9}
  113. //Characters Definition Hex values
  114. // ------------------------------------------------------------------
  115. // W Release type 0-9, A-F
  116. // X Edition type 0-2
  117. // YY SKU of the product 10-35
  118. // ZZZZ Language identifier of the product any required
  119.  
  120. long release = (prodId.Data1 >> (8*3 + 4)) & 0xF;
  121. long sku = (prodId.Data1 >> 16) & 0xFF;
  122.  
  123. if (release < 9)
  124. return; //it's beta or RC
  125.  
  126. switch(sku)
  127. {
  128. case 0x11: //Microsoft Office Professional Enterprise Edition 2003
  129. case 0x12: //Microsoft Office Standard Edition 2003
  130. case 0x13: //Microsoft Office Basic Edition 2003
  131. case 0xCA: //Microsoft Office Small Business Edition 2003
  132. case 0xE3: //Microsoft Office Professional Edition 2003 (with InfoPath 2003)
  133. m_Office2003Installed = true;
  134. break;
  135. default:
  136. ;
  137. }
  138. }
  139.  
  140. void CheckOffice2007(GUID prodId)
  141. {
  142. //KB 928516
  143. //{BRMMmmmm-PPPP-LLLL-p000-0000000FF1CE}
  144. //Characters Definition Hexadecimal values
  145. // ------------------------------------------------------------------
  146. // B Release version 0-9, A-F
  147. // R Release type 0-9, A-F
  148. // MM Major version 0-9
  149. // mmmm Minor version 0-9
  150. // PPPP Product ID 0-9, A-F
  151. // LLLL Language Identifier 0-9, A-F
  152. // p 0 for x86, 1 for x64 0-1
  153. // 000 Reserved for future use, currently 0 0
  154. // D 1 for debug, 0 for ship 0-1
  155. // 000000FF1CE Office Family ID 0-9
  156.  
  157. GUID pattern;
  158. ::IIDFromString(L"{00000000-0000-0000-0000-0000000FF1CE}",&pattern);
  159. if (0 != memcmp(pattern.Data4,prodId.Data4,sizeof(pattern.Data4)))
  160. return;
  161.  
  162. long releaseVer = (prodId.Data1 >> (8*3 + 4)) & 0xF;
  163. if (releaseVer < 9)
  164. return; //it's beta or RC
  165. switch(prodId.Data2)
  166. {
  167. case 0x0011: //Microsoft Office Professional Plus 2007
  168. case 0x0012: //Microsoft Office Standard 2007
  169. case 0x0013: //Microsoft Office Basic 2007
  170. case 0x0014: //Microsoft Office Professional 2007
  171. case 0x002E: //Microsoft Office Ultimate 2007
  172. case 0x002F: //Microsoft Office Home and Student 2007
  173. case 0x0030: //Microsoft Office Enterprise 2007
  174. case 0x00CA: //Microsoft Office Small Business 2007
  175. m_Office2007Installed = true;
  176. break;
  177. default:
  178. ;
  179. }
  180. }
  181.  
  182. bool m_OfficeXPInstalled;
  183. bool m_Office2000Installed;
  184. bool m_Office2003Installed;
  185. bool m_Office2007Installed;
  186.  
  187. public:
  188. OfficeProductChecker()
  189. {
  190. m_OfficeXPInstalled = false;
  191. m_Office2000Installed = false;
  192. m_Office2003Installed = false;
  193. m_Office2007Installed = false;
  194. }
  195. bool OfficeXPInstalled() const { return m_OfficeXPInstalled; }
  196. bool Office2000Installed() const { return m_Office2000Installed; }
  197. bool Office2003Installed() const { return m_Office2003Installed; }
  198. bool Office2007Installed() const { return m_Office2007Installed; }
  199. bool OfficeInstalled() const{
  200. return OfficeXPInstalled() || Office2000Installed() || Office2003Installed() || Office2007Installed();
  201. }
  202. bool IsOfficeProductId(const wchar_t* prodID)
  203. {
  204. GUID pid;
  205. ::IIDFromString((LPOLESTR)prodID,&pid);
  206. CheckProductID(pid);
  207. return OfficeInstalled();
  208. }
  209. };
  210.  
  211. void Test(PCWSTR prodId)
  212. {
  213. OfficeProductChecker checker;
  214. wprintf(L"%s is offfice: %s\n", prodId, checker.IsOfficeProductId(prodId) ? L"Yes" : L"No");
  215. }
  216.  
  217. int _tmain(int argc, _TCHAR* argv[])
  218. {
  219. OfficeProductChecker checker;
  220. checker.DoCheck ();
  221. wprintf(L"Office installed: %s\n", checker.OfficeInstalled() ? L"Yes" : L"No");
  222.  
  223. //Office 2k
  224. Test(L"{00000409-78E1-11D2-B60F-006097C998E7}");
  225. //Office XP beta ?
  226. Test(L"{20280409-6000-11D3-8CFE-0050048383C9}");
  227.  
  228. //Office XP + FrontPage
  229. Test(L"{90280409-6000-11D3-8CFE-0050048383C9}");
  230.  
  231. //Office XP Pro RUS
  232. Test(L"{91110419-6000-11D3-8CFE-0050048383C9}");
  233. //Office 2k3 Prof
  234. Test(L"{90110409-6000-11D3-8CFE-0150048383C9}");
  235.  
  236. //Office 2k3 Std
  237. Test(L"{91120409-6000-11D3-8CFE-0150048383C9}");
  238.  
  239. //Office 2k3 Rus
  240. Test(L"{90110419-6000-11D3-8CFE-0150048383C9}");
  241.  
  242. //Office 2k7 Enterprise
  243. Test(L"{90120000-0030-0000-0000-0000000FF1CE}");
  244. //Office 2k7 Professional
  245. Test(L"{90120000-0014-0000-0000-0000000FF1CE}");
  246.  
  247. //Office 2k7 Professional Plus
  248. Test(L"{90120000-0011-0000-0000-0000000FF1CE}");
  249.  
  250. //Office 2k7 Small Business
  251. Test(L"{90120000-00CA-0000-0000-0000000FF1CE}");
  252.  
  253. //Office 2k7 Standard
  254. Test(L"{90120000-0012-0000-0000-0000000FF1CE}");
  255.  
  256. return 0;
  257. }
Откопал таки
Ссылки на KB в коде но ПРЕДУПРЕЖДАЮ — оригиналы от MS содержат опечатки.

Оригинал: http://rsdn.ru/forum/Message.aspx?mid=2458524&only=1

+добавить реализацию