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.

178 lines
6.1 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. PCH_Driver.CPP
  5. Abstract:
  6. WBEM provider class implementation for PCH_Driver class
  7. Revision History:
  8. Ghim-Sim Chua (gschua) 04/27/99
  9. - Created
  10. Brijesh Krishnaswami (brijeshk) 05/24/99
  11. - added code for enumerating usermode drivers
  12. - added code for enumerating msdos drivers
  13. - added code for getting details on kernel mode drivers
  14. ********************************************************************/
  15. #include "pchealth.h"
  16. #include "PCH_Driver.h"
  17. #include "drvdefs.h"
  18. #include "shlwapi.h"
  19. #define Not_VxD
  20. #include <vxdldr.h> /* For DeviceInfo */
  21. /////////////////////////////////////////////////////////////////////////////
  22. // tracing stuff
  23. #ifdef THIS_FILE
  24. #undef THIS_FILE
  25. #endif
  26. static char __szTraceSourceFile[] = __FILE__;
  27. #define THIS_FILE __szTraceSourceFile
  28. #define TRACE_ID DCID_DRIVER
  29. #define SYSTEM_INI_MAX 32767
  30. CPCH_Driver MyPCH_DriverSet (PROVIDER_NAME_PCH_DRIVER, PCH_NAMESPACE) ;
  31. void MakeSrchDirs(void);
  32. static BOOL fThunkInit = FALSE;
  33. TCHAR g_rgSrchDir[10][MAX_PATH];
  34. UINT g_nSrchDir;
  35. // Property names
  36. //===============
  37. const static WCHAR* pCategory = L"Category" ;
  38. const static WCHAR* pTimeStamp = L"TimeStamp" ;
  39. const static WCHAR* pChange = L"Change" ;
  40. const static WCHAR* pDate = L"Date" ;
  41. const static WCHAR* pDescription = L"Description" ;
  42. const static WCHAR* pLoadedFrom = L"LoadedFrom" ;
  43. const static WCHAR* pManufacturer = L"Manufacturer" ;
  44. const static WCHAR* pName = L"Name" ;
  45. const static WCHAR* pPartOf = L"PartOf" ;
  46. const static WCHAR* pPath = L"Path" ;
  47. const static WCHAR* pSize = L"Size" ;
  48. const static WCHAR* pType = L"Type" ;
  49. const static WCHAR* pVersion = L"Version" ;
  50. CComBSTR bstrPath = L"PathName";
  51. /*****************************************************************************
  52. *
  53. * FUNCTION : CPCH_Driver::EnumerateInstances
  54. *
  55. * DESCRIPTION : Returns all the instances of this class.
  56. *
  57. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  58. * A long that contains the flags described in
  59. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  60. * flags are handled by (and filtered out by) WinMgmt:
  61. * WBEM_FLAG_DEEP
  62. * WBEM_FLAG_SHALLOW
  63. * WBEM_FLAG_RETURN_IMMEDIATELY
  64. * WBEM_FLAG_FORWARD_ONLY
  65. * WBEM_FLAG_BIDIRECTIONAL
  66. *
  67. * RETURNS : WBEM_S_NO_ERROR if successful
  68. *
  69. * COMMENTS : TO DO: All instances on the machine should be returned here.
  70. * If there are no instances, return WBEM_S_NO_ERROR.
  71. * It is not an error to have no instances.
  72. *
  73. *****************************************************************************/
  74. HRESULT CPCH_Driver::EnumerateInstances(
  75. MethodContext* pMethodContext,
  76. long lFlags
  77. )
  78. {
  79. USES_CONVERSION;
  80. TraceFunctEnter("CPCH_Driver::AddDriverKernelList");
  81. HRESULT hRes = WBEM_S_NO_ERROR;
  82. CFileVersionInfo fileversioninfo;
  83. CComVariant varValue;
  84. CComPtr<IEnumWbemClassObject> pEnumInst;
  85. CComPtr<IWbemClassObject> pFileObj;
  86. IWbemClassObjectPtr pObj;
  87. ULONG ulRetVal;
  88. //
  89. // Get the date and time
  90. SYSTEMTIME stUTCTime;
  91. GetSystemTime(&stUTCTime);
  92. // execute query
  93. hRes = ExecWQLQuery(&pEnumInst, CComBSTR("SELECT * FROM Win32_SystemDriver"));
  94. if (FAILED(hRes))
  95. goto done;
  96. while(WBEM_S_NO_ERROR == pEnumInst->Next(WBEM_INFINITE, 1, &pObj, &ulRetVal))
  97. {
  98. // Create a new instance
  99. CInstancePtr pInstance(CreateNewInstance(pMethodContext), false);
  100. // Set the timestamp
  101. if (!pInstance->SetDateTime(pTimeStamp, WBEMTime(stUTCTime)))
  102. ErrorTrace(TRACE_ID, "SetDateTime on Timestamp Field failed.");
  103. // Set the category
  104. if (!pInstance->SetCHString(pCategory, "Kernel"))
  105. ErrorTrace(TRACE_ID, "SetVariant on Category Field failed.");
  106. CopyProperty(pObj, L"Name", pInstance, pName);
  107. hRes = pObj->Get(bstrPath, 0, &varValue, NULL, NULL);
  108. // if we fail to get the path (or it's an empty string) then just copy the
  109. // description from the Win32_SystemDriver class & be done with it...
  110. if (FAILED(hRes) || V_VT(&varValue) != VT_BSTR || V_BSTR(&varValue) == NULL ||
  111. SysStringLen(V_BSTR(&varValue)) == 0)
  112. {
  113. CopyProperty(pObj, L"Description", pInstance, pDescription);
  114. }
  115. // otherwise, use the file object to get the properties
  116. else
  117. {
  118. if (SUCCEEDED(GetCIMDataFile(V_BSTR(&varValue), &pFileObj, TRUE)))
  119. {
  120. // Using the CIM_DataFile object, copy over the appropriate properties.
  121. CopyProperty(pFileObj, L"Version", pInstance, pVersion);
  122. CopyProperty(pFileObj, L"FileSize", pInstance, pSize);
  123. CopyProperty(pFileObj, L"CreationDate", pInstance, pDate);
  124. CopyProperty(pFileObj, L"Name", pInstance, pPath);
  125. CopyProperty(pFileObj, L"Manufacturer", pInstance, pManufacturer);
  126. }
  127. /*
  128. if (SUCCEEDED(fileversioninfo.QueryFile(V_BSTR(&varValue), TRUE)))
  129. {
  130. if (!pInstance->SetCHString(pDescription, fileversioninfo.GetDescription()))
  131. ErrorTrace(TRACE_ID, "SetCHString on description field failed.");
  132. if (!pInstance->SetCHString(pPartOf, fileversioninfo.GetProduct()))
  133. ErrorTrace(TRACE_ID, "SetCHString on partof field failed.");
  134. }
  135. */ }
  136. hRes = pInstance->Commit();
  137. if (FAILED(hRes))
  138. ErrorTrace(TRACE_ID, "Commit on Instance failed.");
  139. }
  140. done:
  141. TraceFunctLeave();
  142. return hRes;
  143. }