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.

146 lines
5.8 KiB

  1. // *********************************************************************************
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // Module Name:
  6. //
  7. // WMI.h
  8. //
  9. // Abstract:
  10. //
  11. // Common functionality for WMI
  12. //
  13. // Author:
  14. //
  15. // Sunil G.V.N. Murali ([email protected]) 22-Dec-2000
  16. //
  17. // Revision History:
  18. //
  19. // Sunil G.V.N. Murali ([email protected]) 22-Dec-2000 : Created It.
  20. //
  21. // *********************************************************************************
  22. #ifndef __WMI_H
  23. #define __WMI_H
  24. //
  25. // macros
  26. //
  27. #define SAFE_RELEASE( interfacepointer ) \
  28. if ( (interfacepointer) != NULL ) \
  29. { \
  30. (interfacepointer)->Release(); \
  31. (interfacepointer) = NULL; \
  32. } \
  33. 1
  34. #define SAFE_EXECUTE( statement ) \
  35. hr = statement; \
  36. if ( FAILED( hr ) ) \
  37. { \
  38. _com_issue_error( hr ); \
  39. } \
  40. 1
  41. //
  42. // define(s) / enumerators / constants
  43. //
  44. #define WMI_NAMESPACE_CIMV2 L"root\\cimv2"
  45. #define WMI_NAMESPACE_DEFAULT L"root\\default"
  46. #define WMI_CLAUSE_AND L"AND"
  47. #define WMI_CLAUSE_OR L"OR"
  48. #define WMI_CLAUSE_WHERE L"WHERE"
  49. #define CLASS_CIMV2_Win32_OperatingSystem L"Win32_OperatingSystem"
  50. #define WMI_REGISTRY L"StdRegProv"
  51. #define WMI_REGISTRY_M_STRINGVALUE L"GetStringValue"
  52. #define WMI_REGISTRY_M_DWORDVALUE L"GetDwordValue"
  53. #define WMI_REGISTRY_IN_HDEFKEY L"hDefKey"
  54. #define WMI_REGISTRY_IN_SUBKEY L"sSubKeyName"
  55. #define WMI_REGISTRY_IN_VALUENAME L"sValueName"
  56. #define WMI_REGISTRY_OUT_VALUE L"sValue"
  57. #define WMI_REGISTRY_OUT_VALUE_DWORD L"uValue"
  58. #define WMI_REGISTRY_OUT_RETURNVALUE L"ReturnValue"
  59. #define WMI_HKEY_CLASSES_ROOT 2147483648
  60. #define WMI_HKEY_CURRENT_USER 2147483649
  61. #define WMI_HKEY_LOCAL_MACHINE 2147483650
  62. #define WMI_HKEY_USERS 2147483651
  63. #define WMI_HKEY_CURRENT_CONFIG 2147482652
  64. // messages
  65. // #define ERROR_COM_ERROR GetResString( IDS_ERROR_COM_ERROR )
  66. //
  67. // function prototype(s)
  68. //
  69. BOOL InitializeCom( IWbemLocator** ppLocator );
  70. BOOL ConnectWmi( IWbemLocator* pLocator,
  71. IWbemServices** ppServices,
  72. LPCWSTR pwszServer, LPCWSTR pwszUser, LPCWSTR pwszPassword,
  73. COAUTHIDENTITY** ppAuthIdentity,
  74. BOOL bCheckWithNullPwd = FALSE,
  75. LPCWSTR pwszNamespace = WMI_NAMESPACE_CIMV2,
  76. HRESULT* phr = NULL, BOOL* pbLocalSystem = NULL, IWbemContext* pWbemContext = NULL );
  77. BOOL ConnectWmiEx( IWbemLocator* pLocator,
  78. IWbemServices** ppServices,
  79. LPCWSTR pwszServer, CHString& strUserName, CHString& strPassword,
  80. COAUTHIDENTITY** ppAuthIdentity, BOOL bNeedPassword = FALSE,
  81. LPCWSTR pszNamespace = WMI_NAMESPACE_CIMV2, BOOL* pbLocalSystem = NULL,
  82. DWORD dwPasswordLen = 0, IWbemContext* pWbemContext = NULL );
  83. BOOL IsValidServerEx( LPCWSTR pwszServer, BOOL& bLocalSystem );
  84. HRESULT SetInterfaceSecurity( IUnknown* pInterface, COAUTHIDENTITY* pAuthIdentity );
  85. VOID WINAPI WbemFreeAuthIdentity( COAUTHIDENTITY** ppAuthIdentity );
  86. VOID WMISaveError( HRESULT hrError );
  87. HRESULT PropertyGet(
  88. IWbemClassObject* pWmiObject,
  89. LPCWSTR pwszProperty,
  90. VARIANT* pvarValue );
  91. HRESULT PropertyGet( IWbemClassObject* pWmiObject,
  92. LPCWSTR pwszProperty, _variant_t& varValue );
  93. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty,
  94. CHString& strValue, LPCWSTR pwszDefault = V_NOT_AVAILABLE );
  95. BOOL PropertyGet( IWbemClassObject* pWmiObject,
  96. LPCWSTR pwszProperty, DWORD& dwValue, DWORD dwDefault = 0 );
  97. BOOL PropertyGet( IWbemClassObject* pWmiObject,
  98. LPCWSTR pwszProperty, BOOL& dwValue, BOOL bDefault = FALSE );
  99. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, ULONGLONG& ullValue );
  100. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, WBEMTime& wbemtime );
  101. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, SYSTEMTIME& systime );
  102. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, TARRAY arr );
  103. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, DWORD dwValue );
  104. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, LPCWSTR pwszValue );
  105. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, _variant_t& varValue );
  106. DWORD GetTargetVersionEx( IWbemServices* pWbemServices, COAUTHIDENTITY* pAuthIdentity );
  107. BOOL RegQueryValueWMI( IWbemServices* pWbemServices, DWORD dwHDefKey,
  108. LPCWSTR pwszSubKeyName, LPCWSTR pwszValueName,
  109. CHString& strValue, LPCWSTR pwszDefault = V_NOT_AVAILABLE );
  110. BOOL RegQueryValueWMI( IWbemServices* pWbemServices,
  111. DWORD dwHDefKey, LPCWSTR pwszSubKeyName,
  112. LPCWSTR pwszValueName, DWORD& dwValue, DWORD dwDefault = 0 );
  113. BOOL GetPropertyFromSafeArray( SAFEARRAY *pSafeArray, LONG lIndex, CHString& strValue,
  114. VARTYPE vartype );
  115. BOOL GetPropertyFromSafeArray( SAFEARRAY *pSafeArray, LONG lIndex,
  116. IWbemClassObject **pScriptObject, VARTYPE vartype );
  117. //
  118. // inline functions
  119. //
  120. // ***************************************************************************
  121. // Routine Description:
  122. //
  123. // Arguments:
  124. //
  125. // Return Value:
  126. //
  127. // ***************************************************************************
  128. inline VOID WMISaveError( _com_error& e )
  129. {
  130. WMISaveError( e.Error() );
  131. }
  132. #endif // __WMI_H