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.

141 lines
5.5 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( IWbemClassObject* pWmiObject,
  88. LPCWSTR pwszProperty, _variant_t& varValue );
  89. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty,
  90. CHString& strValue, LPCWSTR pwszDefault = V_NOT_AVAILABLE );
  91. BOOL PropertyGet( IWbemClassObject* pWmiObject,
  92. LPCWSTR pwszProperty, DWORD& dwValue, DWORD dwDefault = 0 );
  93. BOOL PropertyGet( IWbemClassObject* pWmiObject,
  94. LPCWSTR pwszProperty, BOOL& dwValue, BOOL bDefault = FALSE );
  95. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, ULONGLONG& ullValue );
  96. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, WBEMTime& wbemtime );
  97. BOOL PropertyGet( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, SYSTEMTIME& systime );
  98. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, DWORD dwValue );
  99. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, LPCWSTR pwszValue );
  100. HRESULT PropertyPut( IWbemClassObject* pWmiObject, LPCWSTR pwszProperty, _variant_t& varValue );
  101. DWORD GetTargetVersionEx( IWbemServices* pWbemServices, COAUTHIDENTITY* pAuthIdentity );
  102. BOOL RegQueryValueWMI( IWbemServices* pWbemServices, DWORD dwHDefKey,
  103. LPCWSTR pwszSubKeyName, LPCWSTR pwszValueName,
  104. CHString& strValue, LPCWSTR pwszDefault = V_NOT_AVAILABLE );
  105. BOOL RegQueryValueWMI( IWbemServices* pWbemServices,
  106. DWORD dwHDefKey, LPCWSTR pwszSubKeyName,
  107. LPCWSTR pwszValueName, DWORD& dwValue, DWORD dwDefault = 0 );
  108. BOOL GetPropertyFromSafeArray( SAFEARRAY *pSafeArray, LONG lIndex, CHString& strValue,
  109. VARTYPE vartype );
  110. BOOL GetPropertyFromSafeArray( SAFEARRAY *pSafeArray, LONG lIndex,
  111. IWbemClassObject **pScriptObject, VARTYPE vartype );
  112. //
  113. // inline functions
  114. //
  115. // ***************************************************************************
  116. // Routine Description:
  117. //
  118. // Arguments:
  119. //
  120. // Return Value:
  121. //
  122. // ***************************************************************************
  123. inline VOID WMISaveError( _com_error& e )
  124. {
  125. WMISaveError( e.Error() );
  126. }
  127. #endif // __WMI_H