Source code of Windows XP (NT5)
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.

130 lines
4.3 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_IN_HDEFKEY L"hDefKey"
  53. #define WMI_REGISTRY_IN_SUBKEY L"sSubKeyName"
  54. #define WMI_REGISTRY_IN_VALUENAME L"sValueName"
  55. #define WMI_REGISTRY_OUT_VALUE L"sValue"
  56. #define WMI_REGISTRY_OUT_RETURNVALUE L"ReturnValue"
  57. #define WMI_HKEY_CLASSES_ROOT 2147483648
  58. #define WMI_HKEY_CURRENT_USER 2147483649
  59. #define WMI_HKEY_LOCAL_MACHINE 2147483650
  60. #define WMI_HKEY_USERS 2147483651
  61. #define WMI_HKEY_CURRENT_CONFIG 2147482652
  62. // messages
  63. // #define ERROR_COM_ERROR GetResString( IDS_ERROR_COM_ERROR )
  64. //
  65. // function prototype(s)
  66. //
  67. BOOL InitializeCom( IWbemLocator** ppLocator );
  68. BOOL ConnectWmi( IWbemLocator* pLocator,
  69. IWbemServices** ppServices,
  70. LPCWSTR pwszServer, LPCWSTR pwszUser, LPCWSTR pwszPassword,
  71. COAUTHIDENTITY** ppAuthIdentity,
  72. BOOL bCheckWithNullPwd = FALSE,
  73. LPCWSTR pwszNamespace = WMI_NAMESPACE_CIMV2,
  74. HRESULT* phr = NULL, BOOL* pbLocalSystem = NULL );
  75. BOOL ConnectWmiEx( IWbemLocator* pLocator,
  76. IWbemServices** ppServices,
  77. LPCWSTR pwszServer, CHString& strUserName, CHString& strPassword,
  78. COAUTHIDENTITY** ppAuthIdentity, BOOL bNeedPassword = FALSE,
  79. LPCWSTR pszNamespace = WMI_NAMESPACE_CIMV2, BOOL* pbLocalSystem = NULL );
  80. BOOL IsValidServerEx( LPCWSTR pwszServer, BOOL& bLocalSystem );
  81. HRESULT SetInterfaceSecurity( IUnknown* pInterface, COAUTHIDENTITY* pAuthIdentity );
  82. VOID WINAPI WbemFreeAuthIdentity( COAUTHIDENTITY** ppAuthIdentity );
  83. VOID WMISaveError( HRESULT hrError );
  84. HRESULT PropertyGet( IWbemClassObject* pWmiObject,
  85. LPCWSTR pwszProperty, _variant_t& varValue );
  86. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty,
  87. CHString& strValue, LPCWSTR pwszDefault = V_NOT_AVAILABLE );
  88. BOOL PropertyGet( IWbemClassObject* pWmiObject,
  89. LPCWSTR pwszProperty, DWORD& dwValue, DWORD dwDefault = 0 );
  90. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, ULONGLONG& ullValue );
  91. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, WBEMTime& wbemtime );
  92. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, SYSTEMTIME& systime );
  93. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, TARRAY arr );
  94. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, DWORD dwValue );
  95. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, LPCWSTR pwszValue );
  96. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, _variant_t& varValue );
  97. DWORD GetTargetVersionEx( IWbemServices* pWbemServices, COAUTHIDENTITY* pAuthIdentity );
  98. BOOL RegQueryValueWMI( IWbemServices* pWbemServices, DWORD dwHDefKey,
  99. LPCWSTR pwszSubKeyName, LPCWSTR pwszValueName,
  100. CHString& strValue, LPCWSTR pwszDefault = V_NOT_AVAILABLE );
  101. //
  102. // inline functions
  103. //
  104. // ***************************************************************************
  105. // Routine Description:
  106. //
  107. // Arguments:
  108. //
  109. // Return Value:
  110. //
  111. // ***************************************************************************
  112. inline VOID WMISaveError( _com_error& e )
  113. {
  114. WMISaveError( e.Error() );
  115. }
  116. #endif // __WMI_H