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.

129 lines
4.5 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. PCH_NetworkConnection.CPP
  5. Abstract:
  6. WBEM provider class implementation for PCH_NetworkConnection class
  7. Revision History:
  8. Ghim-Sim Chua (gschua) 04/27/99
  9. - Created
  10. Ghim-Sim Chua (gschua) 05/02/99
  11. - Modified code to use CopyProperty function
  12. - Use CComBSTR instead of USES_CONVERSION
  13. ********************************************************************/
  14. #include "pchealth.h"
  15. #include "PCH_NetworkConnection.h"
  16. /////////////////////////////////////////////////////////////////////////////
  17. // tracing stuff
  18. #ifdef THIS_FILE
  19. #undef THIS_FILE
  20. #endif
  21. static char __szTraceSourceFile[] = __FILE__;
  22. #define THIS_FILE __szTraceSourceFile
  23. #define TRACE_ID DCID_NETWORKCONNECTION
  24. CPCH_NetworkConnection MyPCH_NetworkConnectionSet (PROVIDER_NAME_PCH_NETWORKCONNECTION, PCH_NAMESPACE) ;
  25. // Property names
  26. //===============
  27. const static WCHAR* pTimeStamp = L"TimeStamp" ;
  28. const static WCHAR* pChange = L"Change" ;
  29. const static WCHAR* pLocalName = L"LocalName" ;
  30. const static WCHAR* pName = L"Name" ;
  31. const static WCHAR* pRemoteName = L"RemoteName" ;
  32. const static WCHAR* pStatus = L"Status" ;
  33. const static WCHAR* pType = L"Type" ;
  34. /*****************************************************************************
  35. *
  36. * FUNCTION : CPCH_NetworkConnection::EnumerateInstances
  37. *
  38. * DESCRIPTION : Returns all the instances of this class.
  39. *
  40. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  41. * A long that contains the flags described in
  42. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  43. * flags are handled by (and filtered out by) WinMgmt:
  44. * WBEM_FLAG_DEEP
  45. * WBEM_FLAG_SHALLOW
  46. * WBEM_FLAG_RETURN_IMMEDIATELY
  47. * WBEM_FLAG_FORWARD_ONLY
  48. * WBEM_FLAG_BIDIRECTIONAL
  49. *
  50. * RETURNS : WBEM_S_NO_ERROR if successful
  51. *
  52. * COMMENTS : TO DO: All instances on the machine should be returned here.
  53. * If there are no instances, return WBEM_S_NO_ERROR.
  54. * It is not an error to have no instances.
  55. *
  56. *****************************************************************************/
  57. HRESULT CPCH_NetworkConnection::EnumerateInstances(
  58. MethodContext* pMethodContext,
  59. long lFlags
  60. )
  61. {
  62. TraceFunctEnter("CPCH_NetworkConnection::EnumerateInstances");
  63. HRESULT hRes = WBEM_S_NO_ERROR;
  64. REFPTRCOLLECTION_POSITION posList;
  65. CComPtr<IEnumWbemClassObject> pEnumInst;
  66. IWbemClassObjectPtr pObj; // BUGBUG : WMI asserts if we use CComPtr
  67. ULONG ulRetVal;
  68. // Get the date and time
  69. //
  70. SYSTEMTIME stUTCTime;
  71. GetSystemTime(&stUTCTime);
  72. //
  73. // Execute the query
  74. //
  75. hRes = ExecWQLQuery(&pEnumInst, CComBSTR("select Name, LocalName, RemoteName, ResourceType, Status from Win32_NetworkConnection"));
  76. if (FAILED(hRes))
  77. goto END;
  78. //
  79. // enumerate the instances from win32_CodecFile
  80. //
  81. while(WBEM_S_NO_ERROR == pEnumInst->Next(WBEM_INFINITE, 1, &pObj, &ulRetVal))
  82. {
  83. // Create a new instance based on the passed-in MethodContext
  84. CInstancePtr pInstance(CreateNewInstance(pMethodContext), false);
  85. if (!pInstance->SetDateTime(pTimeStamp, WBEMTime(stUTCTime)))
  86. ErrorTrace(TRACE_ID, "SetDateTime on Timestamp Field failed.");
  87. if (!pInstance->SetCHString(pChange, L"Snapshot"))
  88. ErrorTrace(TRACE_ID, "SetCHString on Change Field failed.");
  89. (void)CopyProperty(pObj, L"LocalName", pInstance, pLocalName);
  90. (void)CopyProperty(pObj, L"Name", pInstance, pName);
  91. (void)CopyProperty(pObj, L"RemoteName", pInstance, pRemoteName);
  92. (void)CopyProperty(pObj, L"Status", pInstance, pStatus);
  93. (void)CopyProperty(pObj, L"ResourceType", pInstance, pType);
  94. hRes = pInstance->Commit();
  95. if (FAILED(hRes))
  96. {
  97. // Could not Set the Change Property
  98. // Continue anyway
  99. ErrorTrace(TRACE_ID, "Set Variant on Name Field failed.");
  100. }
  101. }
  102. END :
  103. TraceFunctLeave();
  104. return hRes ;
  105. }