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.

152 lines
6.0 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 CLASS_CIMV2_Win32_ComputerSystem L"Win32_ComputerSystem"
  51. #define WMI_REGISTRY L"StdRegProv"
  52. #define WMI_REGISTRY_M_STRINGVALUE L"GetStringValue"
  53. #define WMI_REGISTRY_M_DWORDVALUE L"GetDwordValue"
  54. #define WMI_REGISTRY_IN_HDEFKEY L"hDefKey"
  55. #define WMI_REGISTRY_IN_SUBKEY L"sSubKeyName"
  56. #define WMI_REGISTRY_IN_VALUENAME L"sValueName"
  57. #define WMI_REGISTRY_OUT_VALUE L"sValue"
  58. #define WMI_REGISTRY_OUT_VALUE_DWORD L"uValue"
  59. #define WMI_REGISTRY_OUT_RETURNVALUE L"ReturnValue"
  60. #define WMI_HKEY_CLASSES_ROOT 2147483648
  61. #define WMI_HKEY_CURRENT_USER 2147483649
  62. #define WMI_HKEY_LOCAL_MACHINE 2147483650
  63. #define WMI_HKEY_USERS 2147483651
  64. #define WMI_HKEY_CURRENT_CONFIG 2147482652
  65. #define PLATFORM_UNKNOWN 0
  66. #define PLATFORM_X86 1
  67. #define PLATFORM_IA64 2
  68. #define PLATFORM_AMD64 3
  69. #define TEXT_X86 L"X86"
  70. #define TEXT_IA64 L"IA64"
  71. #define TEXT_AMD64 L"AMD64"
  72. // messages
  73. // #define ERROR_COM_ERROR GetResString( IDS_ERROR_COM_ERROR )
  74. //
  75. // function prototype(s)
  76. //
  77. BOOL InitializeCom( IWbemLocator** ppLocator );
  78. BOOL ConnectWmi( IWbemLocator* pLocator,
  79. IWbemServices** ppServices,
  80. LPCWSTR pwszServer, LPCWSTR pwszUser, LPCWSTR pwszPassword,
  81. COAUTHIDENTITY** ppAuthIdentity,
  82. BOOL bCheckWithNullPwd = FALSE,
  83. LPCWSTR pwszNamespace = WMI_NAMESPACE_CIMV2,
  84. HRESULT* phr = NULL, BOOL* pbLocalSystem = NULL, IWbemContext* pWbemContext = NULL );
  85. BOOL ConnectWmiEx( IWbemLocator* pLocator,
  86. IWbemServices** ppServices,
  87. LPCWSTR pwszServer, CHString& strUserName, CHString& strPassword,
  88. COAUTHIDENTITY** ppAuthIdentity, BOOL bNeedPassword = FALSE,
  89. LPCWSTR pszNamespace = WMI_NAMESPACE_CIMV2, BOOL* pbLocalSystem = NULL,
  90. DWORD dwPasswordLen = 0, IWbemContext* pWbemContext = NULL );
  91. BOOL IsValidServerEx( LPCWSTR pwszServer, BOOL& bLocalSystem );
  92. HRESULT SetInterfaceSecurity( IUnknown* pInterface, COAUTHIDENTITY* pAuthIdentity );
  93. VOID WINAPI WbemFreeAuthIdentity( COAUTHIDENTITY** ppAuthIdentity );
  94. VOID WMISaveError( HRESULT hrError );
  95. HRESULT PropertyGet( IWbemClassObject* pWmiObject,
  96. LPCWSTR pwszProperty, _variant_t& varValue );
  97. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty,
  98. CHString& strValue, LPCWSTR pwszDefault = V_NOT_AVAILABLE );
  99. BOOL PropertyGet( IWbemClassObject* pWmiObject,
  100. LPCWSTR pwszProperty, DWORD& dwValue, DWORD dwDefault = 0 );
  101. BOOL PropertyGet( IWbemClassObject* pWmiObject,
  102. LPCWSTR pwszProperty, BOOL& dwValue, BOOL bDefault = FALSE );
  103. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, ULONGLONG& ullValue );
  104. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, WBEMTime& wbemtime );
  105. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, SYSTEMTIME& systime );
  106. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, DWORD dwValue );
  107. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, LPCWSTR pwszValue );
  108. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, _variant_t& varValue );
  109. DWORD GetTargetVersionEx( IWbemServices* pWbemServices, COAUTHIDENTITY* pAuthIdentity );
  110. DWORD GetTargetPlatformEx( IWbemServices* pWbemServices, COAUTHIDENTITY* pAuthIdentity );
  111. BOOL RegQueryValueWMI( IWbemServices* pWbemServices, DWORD dwHDefKey,
  112. LPCWSTR pwszSubKeyName, LPCWSTR pwszValueName,
  113. CHString& strValue, LPCWSTR pwszDefault = V_NOT_AVAILABLE );
  114. BOOL RegQueryValueWMI( IWbemServices* pWbemServices,
  115. DWORD dwHDefKey, LPCWSTR pwszSubKeyName,
  116. LPCWSTR pwszValueName, DWORD& dwValue, DWORD dwDefault = 0 );
  117. BOOL GetPropertyFromSafeArray( SAFEARRAY *pSafeArray, LONG lIndex, CHString& strValue,
  118. VARTYPE vartype );
  119. BOOL GetPropertyFromSafeArray( SAFEARRAY *pSafeArray, LONG lIndex,
  120. IWbemClassObject **pScriptObject, VARTYPE vartype );
  121. //
  122. // inline functions
  123. //
  124. // ***************************************************************************
  125. // Routine Description:
  126. //
  127. // Arguments:
  128. //
  129. // Return Value:
  130. //
  131. // ***************************************************************************
  132. inline VOID WMISaveError( _com_error& e )
  133. {
  134. WMISaveError( e.Error() );
  135. }
  136. #endif // __WMI_H