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.

90 lines
3.1 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 1998-1999 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: wbemcommon.cpp
  6. //
  7. // Project: Chameleon
  8. //
  9. // Description: Common WBEM Related Helper Functions
  10. //
  11. // Log:
  12. //
  13. // When Who What
  14. // ---- --- ----
  15. // 12/03/98 TLP Initial Version
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. #include "stdafx.h"
  19. #include "wbemhlpr.h"
  20. #include <comdef.h>
  21. #include <comutil.h>
  22. //////////////////////////////////////////////////////////////////////////////
  23. //
  24. // Function: ConnectToWM()
  25. //
  26. // Synopsis: Connect to Windows Management
  27. //
  28. //////////////////////////////////////////////////////////////////////////////
  29. HRESULT
  30. ConnectToWM(
  31. /*[out]*/ IWbemServices** ppWbemSrvcs
  32. )
  33. {
  34. HRESULT hr = S_OK;
  35. // Get the WMI Locator
  36. CComPtr<IWbemLocator> pLoc;
  37. hr = CoCreateInstance(
  38. CLSID_WbemLocator,
  39. 0,
  40. CLSCTX_INPROC_SERVER,
  41. IID_IWbemLocator,
  42. (void**)&pLoc
  43. );
  44. if ( SUCCEEDED(hr) )
  45. {
  46. // Connect to the CIMV2 Namespace on the local system
  47. CComPtr<IWbemServices> pWbemSrvcs;
  48. _bstr_t bstrRootNamespace = L"\\\\.\\ROOT\\CIMV2";
  49. hr = pLoc->ConnectServer(
  50. bstrRootNamespace,
  51. NULL,
  52. NULL,
  53. 0,
  54. NULL,
  55. 0,
  56. 0,
  57. &pWbemSrvcs
  58. );
  59. if ( SUCCEEDED(hr) )
  60. {
  61. // Set client security... May only need to do this if a service is
  62. // accessing Windows Management via the Appliance Services DLL
  63. CComPtr<IClientSecurity> pSecurity;
  64. hr = pWbemSrvcs->QueryInterface(IID_IClientSecurity , (void **) &pSecurity);
  65. if ( SUCCEEDED(hr) )
  66. {
  67. hr = pSecurity->SetBlanket (
  68. pWbemSrvcs,
  69. RPC_C_AUTHN_WINNT,
  70. RPC_C_AUTHZ_NONE,
  71. NULL,
  72. RPC_C_AUTHN_LEVEL_CONNECT ,
  73. RPC_C_IMP_LEVEL_IMPERSONATE,
  74. NULL,
  75. EOAC_DYNAMIC_CLOAKING
  76. );
  77. if ( SUCCEEDED(hr) )
  78. {
  79. (*ppWbemSrvcs = pWbemSrvcs)->AddRef();
  80. }
  81. }
  82. }
  83. }
  84. return hr;
  85. }