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.

298 lines
10 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. #if !defined(__SdkWbemHelpers_H)
  3. #define __SdkWbemHelpers_H
  4. #pragma once
  5. #if defined(_SDKWBEMHELPERS) || defined(_BUILD_SDKWBEMHELPERS)
  6. #undef SMSSDK_Export
  7. #if defined(_BUILD_SDKWBEMHELPERS)
  8. #define SMSSDK_Export __declspec(dllexport)
  9. #else
  10. #define SMSSDK_Export __declspec(dllimport)
  11. #endif
  12. #else
  13. #define SMSSDK_Export
  14. #endif
  15. #include <wbemidl.h>
  16. #include <comdef.h>
  17. SMSSDK_Export _bstr_t GetWbemErrorText(HRESULT hr);
  18. class CWbemClassObject;
  19. class CWbemServices;
  20. _COM_SMARTPTR_TYPEDEF(IUnsecuredApartment, IID_IUnsecuredApartment);
  21. _COM_SMARTPTR_TYPEDEF(IWbemObjectSink, IID_IWbemObjectSink);
  22. _COM_SMARTPTR_TYPEDEF(IWbemClassObject, IID_IWbemClassObject);
  23. _COM_SMARTPTR_TYPEDEF(IWbemServices, IID_IWbemServices);
  24. _COM_SMARTPTR_TYPEDEF(IWbemContext, IID_IWbemContext );
  25. _COM_SMARTPTR_TYPEDEF(IWbemCallResult, IID_IWbemCallResult);
  26. _COM_SMARTPTR_TYPEDEF(IWbemQualifierSet, IID_IWbemQualifierSet);
  27. _COM_SMARTPTR_TYPEDEF(IWbemLocator, IID_IWbemLocator);
  28. _COM_SMARTPTR_TYPEDEF(IWbemObjectAccess, IID_IWbemObjectAccess);
  29. _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, IID_IEnumWbemClassObject);
  30. //-----------------------------------------------------------------------------
  31. class SMSSDK_Export CWbemException : public _com_error
  32. {
  33. private:
  34. CWbemClassObject * m_pWbemError;
  35. HRESULT m_hr;
  36. _bstr_t m_sDescription;
  37. static IErrorInfo * GetErrorObject();
  38. static IErrorInfo * MakeErrorObject(_bstr_t);
  39. void GetWbemStatusObject();
  40. public:
  41. CWbemException(HRESULT hr,_bstr_t sMessage);
  42. CWbemException(_bstr_t sMessage);
  43. CWbemClassObject GetWbemError();
  44. _bstr_t GetDescription() { return m_sDescription; }
  45. HRESULT GetErrorCode() { return m_hr; }
  46. };
  47. //-----------------------------------------------------------------------------
  48. class SMSSDK_Export CWbemClassObject
  49. {
  50. private:
  51. IWbemClassObjectPtr m_pWbemObject;
  52. ULONG ref;
  53. public:
  54. CWbemClassObject(const CWbemClassObject& _in);
  55. CWbemClassObject(IWbemClassObject * const _in);
  56. CWbemClassObject(IWbemClassObjectPtr& _in);
  57. CWbemClassObject(IUnknown * _in);
  58. CWbemClassObject(IUnknownPtr& _in);
  59. CWbemClassObject();
  60. ~CWbemClassObject();
  61. ULONG AddRef();
  62. ULONG Release();
  63. void Attach(IWbemClassObject * pWbemObject);
  64. void Attach(IWbemClassObject * pWbemObject,bool bAddRef);
  65. IWbemClassObject * Detach();
  66. IWbemClassObject * operator->();
  67. operator IWbemClassObject*();
  68. operator IWbemClassObject**();
  69. operator IWbemClassObjectPtr();
  70. operator IUnknown *();
  71. IWbemClassObject ** operator &();
  72. IWbemClassObject* operator=(IWbemClassObject* _p);
  73. IWbemClassObjectPtr operator=(IWbemClassObjectPtr& _p);
  74. IWbemClassObject* operator=(IUnknown * _p);
  75. IWbemClassObjectPtr operator=(IUnknownPtr& _p);
  76. IWbemClassObject* operator=(const CWbemClassObject& _p);
  77. bool operator<(const CWbemClassObject& _comp);
  78. bool IsNull() const ;
  79. bool operator !();
  80. operator bool();
  81. unsigned long GetObjectSize();
  82. _bstr_t GetObjectText();
  83. HRESULT Clone(CWbemClassObject& _newObject);
  84. CWbemClassObject SpawnInstance();
  85. // put overloads
  86. HRESULT Put(const _bstr_t& _Name,_variant_t _value,CIMTYPE vType = 0);
  87. HRESULT Put(const _bstr_t& _Name,const _bstr_t& _value,CIMTYPE vType = 0);
  88. HRESULT Put(const _bstr_t& _Name, const long _value, CIMTYPE vType = 0);
  89. HRESULT Put(const _bstr_t& _Name, const bool _value,CIMTYPE vType = 0);
  90. HRESULT Get(const _bstr_t& _Name, _bstr_t& _value);
  91. HRESULT Get(const _bstr_t& _Name, long& _value);
  92. HRESULT Get(const _bstr_t& _Name, bool& _value);
  93. HRESULT Get(const _bstr_t& _Name,_variant_t& _value);
  94. _variant_t Get(const _bstr_t& _Name,CIMTYPE& vType,long& lFlavor);
  95. _bstr_t GetString(const _bstr_t& _Name);
  96. _int64 GetI64(const _bstr_t& _Name);
  97. long GetLong(const _bstr_t& _Name);
  98. bool GetBool(const _bstr_t& _Name);
  99. _bstr_t GetCIMTYPE(const _bstr_t& _Name);
  100. HRESULT GetValueMap (const _bstr_t& _Name, long value, _bstr_t &str);
  101. // these cast string props to the retval.
  102. long GetLongEx(const _bstr_t& _Name);
  103. bool GetBoolEx(const _bstr_t& _Name);
  104. // these cast string props fm the parm.
  105. HRESULT PutEx(const _bstr_t& _Name, const long _value, CIMTYPE vType = 0);
  106. HRESULT PutEx(const _bstr_t& _Name, const bool _value,CIMTYPE vType = 0);
  107. //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  108. CWbemClassObject GetEmbeddedObject(const _bstr_t& _Name);
  109. HRESULT PutEmbeddedObject(const _bstr_t& _Name, CWbemClassObject &obj);
  110. HRESULT GetBLOB(const _bstr_t& _Name, BYTE **ptr, DWORD *outLen = NULL);
  111. HRESULT PutBLOB(const _bstr_t& _Name, const BYTE *ptr, const DWORD len);
  112. HRESULT GetDateTimeFormat(const _bstr_t& _Name, bstr_t &timeStr);
  113. HRESULT GetDIB(const _bstr_t& _Name, HDC hDC, HBITMAP &hDDBitmap);
  114. HRESULT BeginEnumeration(long _lFlags = WBEM_FLAG_LOCAL_ONLY);
  115. HRESULT Next(_bstr_t& _sName,_variant_t& _value);
  116. HRESULT Next(_bstr_t& _sName,_variant_t& _value,CIMTYPE& _vartype);
  117. HRESULT Next(_bstr_t& _sName,_variant_t& _value,CIMTYPE& _vartype,long& _flavor);
  118. HRESULT EndEnumeration();
  119. HRESULT GetMethod(const IN _bstr_t& _name, CWbemClassObject& coInSignature,
  120. CWbemClassObject& coOutSignature, long _lFlags = 0);
  121. private:
  122. int ValidDMTF(bstr_t dmtf);
  123. // helpers for GetDIB().
  124. WORD DibNumColors(LPBITMAPINFOHEADER lpbi);
  125. WORD PaletteSize(LPBITMAPINFOHEADER lpbi);
  126. };
  127. __inline bool operator<(const CWbemClassObject& _X,const CWbemClassObject& _Y)
  128. {
  129. return _X < _Y;
  130. }
  131. __inline bool operator==(const CWbemClassObject& _X,const CWbemClassObject& _Y)
  132. {
  133. return _X == _Y;
  134. }
  135. //-----------------------------------------------------------------------------
  136. typedef struct {
  137. bool currUser;
  138. COAUTHIDENTITY *authIdent;
  139. TCHAR fullAcct[100];
  140. } LOGIN_CREDENTIALS;
  141. class SMSSDK_Export CWbemServices
  142. {
  143. private:
  144. HRESULT GetInterfacePtr(IWbemServicesPtr & pServices,
  145. DWORD _dwProxyCapabilities = EOAC_NONE);
  146. HRESULT CommonInit(IWbemServicesPtr& pServ);
  147. bool IsClientNT5OrMore(void);
  148. HANDLE m_hAccessToken;
  149. LUID m_luid;
  150. bool m_fClearToken;
  151. public:
  152. bool m_cloak; // protects the cloak from eoac.
  153. COAUTHIDENTITY *m_authIdent;
  154. _bstr_t m_path;
  155. HRESULT m_hr;
  156. IWbemServicesPtr m_pService;
  157. IWbemContextPtr m_pCtx;
  158. _bstr_t m_User;
  159. _bstr_t m_Password;
  160. long m_lFlags;
  161. CWbemServices(IWbemContext * _pContext = NULL);
  162. CWbemServices(const CWbemServices& _p, COAUTHIDENTITY *authIdent = 0);
  163. CWbemServices(const IWbemServicesPtr& _in);
  164. CWbemServices(const IUnknownPtr& _in);
  165. CWbemServices(IUnknown * _in);
  166. CWbemServices(IWbemServices *_in,IWbemContext * _pContext = NULL);
  167. ~CWbemServices();
  168. CWbemServices& operator=(IUnknown * _p);
  169. CWbemServices& operator=(IUnknownPtr& _p);
  170. CWbemServices& operator=(IWbemServices *_p);
  171. CWbemServices& operator=(const CWbemServices& _p);
  172. bool IsNull() ;
  173. operator bool();
  174. HRESULT GetServices(IWbemServices ** ppServices);
  175. HRESULT SetBlanket(IUnknown *service,
  176. DWORD _dwProxyCapabilities = EOAC_NONE);
  177. void SetPriv(LPCTSTR privName = SE_SYSTEM_ENVIRONMENT_NAME);
  178. DWORD EnablePriv(bool fEnable );
  179. void ClearPriv(void);
  180. // Login as guest...
  181. HRESULT ConnectServer(_bstr_t sNetworkResource);
  182. // Login as user...
  183. HRESULT ConnectServer(_bstr_t sNetworkResource,
  184. _bstr_t sUser,
  185. _bstr_t sPassword,
  186. long SecurityFlags = 0);
  187. HRESULT ConnectServer(_bstr_t sNetworkResource,
  188. LOGIN_CREDENTIALS *user,
  189. long lSecurityFlags = 0);
  190. CWbemServices OpenNamespace(_bstr_t sNetworkResource);
  191. void DisconnectServer(void);
  192. CWbemClassObject CreateInstance(_bstr_t _sClass, IWbemCallResultPtr& _cr);
  193. CWbemClassObject CreateInstance(_bstr_t _sClass);
  194. HRESULT DeleteInstance(_bstr_t _sClass);
  195. CWbemClassObject GetObject(_bstr_t _sName, IWbemCallResultPtr &_cr, long flags = 0);
  196. CWbemClassObject GetObject(_bstr_t _sName, long flags = 0);
  197. IWbemClassObject *FirstInstanceOf(bstr_t className);
  198. HRESULT PutInstance(CWbemClassObject& _object, IWbemCallResultPtr& _cr,
  199. long _lFlags = WBEM_FLAG_CREATE_OR_UPDATE);
  200. HRESULT PutInstance(CWbemClassObject& _object,
  201. IWbemContext *pContext,
  202. long _lFlags = WBEM_FLAG_CREATE_OR_UPDATE,
  203. DWORD _dwProxyCapabilities = EOAC_NONE);
  204. HRESULT PutInstance(CWbemClassObject& _object,
  205. long _lFlags = WBEM_FLAG_CREATE_OR_UPDATE,
  206. DWORD _dwProxyCapabilities = EOAC_NONE);
  207. HRESULT CreateInstanceEnum(_bstr_t Class, long lFlags, IEnumWbemClassObject **ppEnum);
  208. HRESULT CreateInstanceEnumAsync(_bstr_t Class, IWbemObjectSink * ppSink, long lFlags = 0);
  209. HRESULT CreateClassEnum(_bstr_t Class, long lFlags, IEnumWbemClassObject **ppEnum);
  210. HRESULT ExecQuery(_bstr_t QueryLanguage,_bstr_t Query, long lFlags, IEnumWbemClassObject **ppEnum);
  211. HRESULT ExecQuery(_bstr_t Query, long lFlags, IEnumWbemClassObject **ppEnum);
  212. HRESULT ExecQuery(_bstr_t Query, IEnumWbemClassObject **ppEnum) ;
  213. HRESULT ExecQueryAsync(_bstr_t Query, IWbemObjectSink *pSink, long lFlags = 0);
  214. HRESULT GetMethodSignatures(const _bstr_t& _sObjectName,
  215. const _bstr_t& _sMethodName,
  216. CWbemClassObject& _in,
  217. CWbemClassObject& _out);
  218. HRESULT ExecMethod(_bstr_t sPath,
  219. _bstr_t sMethod,
  220. CWbemClassObject& inParams,
  221. CWbemClassObject& outParams);
  222. HRESULT CancelAsyncCall(IWbemObjectSink * pSink);
  223. HRESULT SetContextValue(_bstr_t sName,_variant_t value);
  224. HRESULT GetContextValue(_bstr_t sName,_variant_t& value);
  225. HRESULT DeleteContextValue(_bstr_t sName);
  226. HRESULT DeleteAllContextValues();
  227. HRESULT SetContext(IWbemContext * pWbemContext);
  228. HRESULT GetContext(IWbemContext ** ppWbemContext);
  229. HRESULT CreateClassEnumAsync(_bstr_t Class,
  230. IWbemObjectSink *ppSink,
  231. long lFlags /*= 0*/);
  232. };
  233. #endif //__SdkWbemHelpers_H