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.

394 lines
11 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. WBEMTEST.H
  5. Abstract:
  6. History:
  7. --*/
  8. #ifndef __WBEMTEST__H_
  9. #define __WBEMTEST__H_
  10. #include <windows.h>
  11. #include <wbemidl.h>
  12. #include <wbemint.h>
  13. //#include <dbgalloc.h>
  14. //#include <arena.h>
  15. #include <WT_wstring.h>
  16. #include <wbemdlg.h>
  17. #include <wbemntfy.h>
  18. #include <resrc1.h>
  19. #define I_EMBEDDED_OBJECT IUnknown
  20. #define VT_EMBEDDED_OBJECT VT_UNKNOWN
  21. #define TOKEN_THREAD 0
  22. #define TOKEN_PROCESS 1
  23. HRESULT EnableAllPrivileges(DWORD dwTokenType = TOKEN_THREAD);
  24. int Trace(const char *fmt, ...);
  25. extern IWbemLocator *g_pLocator;
  26. extern IWbemServices *g_pNamespace;
  27. //extern IWbemServicesEx *g_pServicesEx;
  28. extern BSTR g_strNamespace;
  29. extern BOOL gbSecured;
  30. enum
  31. {
  32. SYNC = 0,
  33. ASYNC = 0x1,
  34. SEMISYNC = 0x2,
  35. USE_NEXTASYNC = 0x1000 // applies to semisync enumeration only
  36. };
  37. void FormatError(SCODE res, HWND hParent, IWbemClassObject* pErrorObj = NULL);
  38. class CQueryResultDlg;
  39. void ShowClass(HWND hDlg, LONG lGenFlags, LPWSTR wszClass,
  40. LONG lSync, CRefCountable* pOwner, LONG lTimeout);
  41. void ShowClasses(HWND hDlg, LONG lGenFlags, LONG lQryFlags, LPWSTR wszParentClass,
  42. LONG lSync, CRefCountable* pOwner, LONG lTimeout, ULONG nBatch);
  43. void ShowInstances(HWND hDlg, LONG lGenFlags, LONG lQryFlags, LPWSTR wszClass,
  44. LONG lSync, CRefCountable* pOwner, LONG lTimeout, ULONG nBatch);
  45. BOOL _ExecQuery(HWND hDlg, LONG lGenFlags, LONG lQryFlags, LPWSTR wszQuery, LPWSTR wszLanguage,
  46. LONG lSync, CQueryResultDlg* pRes, char* pWindowTitle, LONG lTimeout, ULONG nBatch);
  47. BOOL _PutInstance(HWND hDlg, LONG lGenFlags, LONG lChgFlags, LONG lSync,
  48. IWbemClassObject* pInstance, LONG lTimeout);
  49. BOOL _PutClass(HWND hDlg, LONG lGenFlags, LONG lChgFlags, LONG lSync,
  50. IWbemClassObject* pClass, LONG lTimeout);
  51. IWbemClassObject* _CreateInstance(HWND hDlg, LONG lGenFlags, LONG lSync, LONG lTimeout);
  52. IWbemClassObject* PreCreateInstance(HWND hDlg, LONG lGenFlags, LONG lSync, LONG lTimeout);
  53. class CNotSink;
  54. //***************************************************************************
  55. class CQueryResultDlg : public CWbemDialog
  56. {
  57. protected:
  58. CFlexArray m_InternalArray;
  59. CNotSink* m_pHandler;
  60. IWbemObjectSink* m_pWrapper;
  61. IEnumWbemClassObject* m_pEnum; // for synchronous and semisynchronous enumeration
  62. bool m_partial_result;
  63. BOOL m_bRelease;
  64. BOOL m_bReadOnly;
  65. BOOL m_fDeletesAllowed;
  66. BOOL m_bComplete;
  67. BOOL m_bSort;
  68. LONG m_lGenFlags; // generic WBEM_FLAG_ .. flags
  69. LONG m_lQryFlags; // query WBEM_FLAG_ .. flags
  70. LONG m_lSync; // sync, async, semisync
  71. LONG m_lTimeout; // used in semisync only
  72. ULONG m_nBatch; // used in semisync and sync enumerations
  73. ULONG m_nReturnedMax; // maximum size of batch returned
  74. char *m_szTitle;
  75. struct CStatus
  76. {
  77. HRESULT m_hres;
  78. BSTR m_str;
  79. IWbemClassObject* m_pObj;
  80. CStatus(long l, BSTR str, IWbemClassObject* pObj)
  81. : m_hres(l), m_pObj(pObj)
  82. {
  83. m_str = (str ? SysAllocString(str) : NULL);
  84. if(m_pObj) m_pObj->AddRef();
  85. }
  86. ~CStatus()
  87. {
  88. SysFreeString(m_str);
  89. if(m_pObj) m_pObj->Release();
  90. }
  91. };
  92. public:
  93. CQueryResultDlg(HWND hParent, LONG lGenFlags, LONG lQryFlags, BOOL fDeletesAllowed = TRUE, int tID = IDD_QUERY_RESULT);
  94. virtual ~CQueryResultDlg();
  95. void SetNotify(CNotSink* pNotify);
  96. void SetEnum(IEnumWbemClassObject* pEnum, HRESULT = 0);
  97. void SetReadOnly(BOOL bReadOnly = TRUE) { m_bReadOnly = bReadOnly; }
  98. void SetCallMethod(LONG lSync) { m_lSync = lSync; }
  99. void SetTimeout(LONG lTimeout) { m_lTimeout = lTimeout; }
  100. void SetBatchCount(ULONG nBatch) { m_nBatch = nBatch; }
  101. void SetTitle(char* szTitle);
  102. void SetComplete(HRESULT hres, BSTR strParam, IWbemClassObject* pErrorObj);
  103. void AddObject(IWbemClassObject* pObj);
  104. void RunDetached(CRefCountable* pOwner);
  105. void PostObject(IWbemClassObject* pObj);
  106. void PostCount(long nCount);
  107. void PostComplete(long lParam, BSTR strParam, IWbemClassObject* pObjParam);
  108. void set_partial(bool value){ if (m_partial_result==false) m_partial_result = value;}
  109. IWbemObjectSink* GetWrapper() {return m_pWrapper;}
  110. protected:
  111. virtual BOOL OnInitDialog();
  112. virtual BOOL OnCommand(WORD wCode, WORD wID);
  113. virtual BOOL OnUser(WPARAM wParam, LPARAM lParam);
  114. virtual void OnDelete();
  115. virtual void OnAdd();
  116. virtual void OnCopy();
  117. virtual BOOL OnDoubleClick(int nID);
  118. virtual BOOL DeleteListElement(LRESULT nSel);
  119. virtual BOOL ViewListElement(LRESULT nSel);
  120. virtual IWbemClassObject* AddNewElement();
  121. virtual BOOL CanAdd() { return FALSE;}
  122. virtual BOOL CanDelete() { return m_fDeletesAllowed;}
  123. virtual BOOL Initialize() {return TRUE;}
  124. void MakeListEntry(IWbemClassObject* pObj, WString& ListEntry);
  125. void SetNumItems(LRESULT nNum);
  126. void SetNumBatchItems(ULONG nNum);
  127. void RefreshItem(int nItem);
  128. void ProcessEnum();
  129. void ProcessEnumSemisync();
  130. void SemisyncNextAsync();
  131. };
  132. //***************************************************************************
  133. class CAppOwner : public CRefCountable
  134. {
  135. public:
  136. virtual long Release();
  137. };
  138. //***************************************************************************
  139. class CQueryDlg : public CWbemDialog
  140. {
  141. protected:
  142. wchar_t **m_pwszQueryType;
  143. wchar_t **m_pwszQueryString;
  144. static char *m_szLastQueryType;
  145. static char *m_szLastQuery;
  146. LONG* m_plQryFlags;
  147. public:
  148. CQueryDlg(HWND hParent, LONG* plQryFlags, LPWSTR *pwszQueryString, LPWSTR *pwszQueryType)
  149. : CWbemDialog(IDD_QUERY, hParent), m_plQryFlags(plQryFlags),
  150. m_pwszQueryType(pwszQueryType), m_pwszQueryString(pwszQueryString)
  151. {}
  152. protected:
  153. BOOL OnInitDialog();
  154. BOOL Verify();
  155. };
  156. class CContext
  157. {
  158. protected:
  159. BOOL m_bNull;
  160. IWbemContext* m_pContext;
  161. public:
  162. CContext();
  163. ~CContext();
  164. BOOL IsNull() {return m_bNull;}
  165. IWbemContext* GetStoredContext() {return m_pContext;}
  166. INT_PTR Edit(HWND hParent);
  167. operator IWbemContext*();
  168. IWbemContext* operator->() {return (IWbemContext*)*this;}
  169. void operator=(const CContext& Other);
  170. BOOL SetNullness(BOOL bNull);
  171. void Clear();
  172. };
  173. extern CContext g_Context;
  174. //***************************************************************************
  175. class CRefresherDlg : public CQueryResultDlg
  176. {
  177. protected:
  178. IWbemRefresher* m_pRefresher;
  179. IWbemConfigureRefresher* m_pCreator;
  180. CFlexArray m_aIds;
  181. CFlexArray m_apEnums;
  182. public:
  183. CRefresherDlg(HWND hParent, LONG lGenFlags);
  184. ~CRefresherDlg();
  185. virtual BOOL OnInitDialog();
  186. virtual BOOL OnCommand(WORD wCode, WORD wID);
  187. virtual void OnRefresh();
  188. virtual IWbemClassObject* AddNewElement();
  189. virtual BOOL DeleteListElement(LRESULT nSel);
  190. virtual BOOL OnDoubleClick( int nID );
  191. virtual BOOL CanAdd() { return TRUE;}
  192. };
  193. //***************************************************************************
  194. class CRefresherEnumDlg : public CQueryResultDlg
  195. {
  196. protected:
  197. IWbemHiPerfEnum* m_pEnum;
  198. char* m_pszName;
  199. public:
  200. CRefresherEnumDlg(HWND hParent, LONG lGenFlags, IWbemHiPerfEnum* pEnum, char* pszName);
  201. ~CRefresherEnumDlg();
  202. virtual BOOL OnInitDialog();
  203. virtual BOOL CanAdd() { return FALSE;}
  204. };
  205. //***************************************************************************
  206. class CHourGlass
  207. {
  208. protected:
  209. HCURSOR m_hCursor;
  210. public:
  211. CHourGlass();
  212. ~CHourGlass();
  213. };
  214. //***************************************************************************
  215. void Fatal(UINT uMsg);
  216. class CUnsecWrap
  217. {
  218. protected:
  219. IWbemObjectSink* m_pSink;
  220. IWbemObjectSink* m_pWrapper;
  221. static IUnsecuredApartment* mstatic_pApartment;
  222. protected:
  223. static void Init()
  224. {
  225. if(mstatic_pApartment == NULL && gbSecured)
  226. {
  227. HRESULT hres = CoCreateInstance(CLSID_UnsecuredApartment, NULL,
  228. CLSCTX_ALL,
  229. IID_IUnsecuredApartment,
  230. (void**)&mstatic_pApartment);
  231. if(FAILED(hres))
  232. {
  233. Fatal(IDS_OLE_INIT_FAILED);
  234. }
  235. }
  236. }
  237. public:
  238. CUnsecWrap(IWbemObjectSink* pSink) : m_pSink(pSink), m_pWrapper(NULL)
  239. {
  240. m_pSink->AddRef();
  241. Init();
  242. }
  243. ~CUnsecWrap()
  244. {
  245. m_pSink->Release();
  246. if(m_pWrapper)
  247. m_pWrapper->Release();
  248. }
  249. operator IWbemObjectSink*()
  250. {
  251. if(!gbSecured)
  252. return m_pSink;
  253. if(m_pWrapper)
  254. return m_pWrapper;
  255. IUnknown* pUnk = NULL;
  256. SCODE sc = mstatic_pApartment->CreateObjectStub(m_pSink, &pUnk);
  257. if(sc != S_OK || pUnk == NULL)
  258. {
  259. Fatal(IDS_UNSECAPP_ERROR);
  260. FormatError(sc, NULL);
  261. return NULL;
  262. }
  263. pUnk->QueryInterface(IID_IWbemObjectSink, (void**)&m_pWrapper);
  264. pUnk->Release();
  265. return m_pWrapper;
  266. }
  267. };
  268. class CUnsecWrapEx
  269. {
  270. protected:
  271. IWbemObjectSink* m_pSink;
  272. IWbemObjectSink* m_pWrapper;
  273. static IUnsecuredApartment* mstatic_pApartment;
  274. protected:
  275. static void Init()
  276. {
  277. if(mstatic_pApartment == NULL && gbSecured)
  278. {
  279. HRESULT hres = CoCreateInstance(CLSID_UnsecuredApartment, NULL,
  280. CLSCTX_ALL,
  281. IID_IUnsecuredApartment,
  282. (void**)&mstatic_pApartment);
  283. if(FAILED(hres))
  284. {
  285. Fatal(IDS_OLE_INIT_FAILED);
  286. }
  287. }
  288. }
  289. public:
  290. CUnsecWrapEx(IWbemObjectSink* pSink) : m_pSink(pSink), m_pWrapper(NULL)
  291. {
  292. m_pSink->AddRef();
  293. Init();
  294. }
  295. ~CUnsecWrapEx()
  296. {
  297. m_pSink->Release();
  298. if(m_pWrapper)
  299. m_pWrapper->Release();
  300. }
  301. operator IWbemObjectSink*()
  302. {
  303. if(!gbSecured)
  304. return m_pSink;
  305. if(m_pWrapper)
  306. return m_pWrapper;
  307. IUnknown* pUnk = NULL;
  308. SCODE sc = mstatic_pApartment->CreateObjectStub(m_pSink, &pUnk);
  309. if(sc != S_OK || pUnk == NULL)
  310. {
  311. Fatal(IDS_UNSECAPP_ERROR);
  312. FormatError(sc, NULL);
  313. return NULL;
  314. }
  315. pUnk->QueryInterface(IID_IWbemObjectSink, (void**)&m_pWrapper);
  316. pUnk->Release();
  317. return m_pWrapper;
  318. }
  319. };
  320. #endif