none
SetupDiEnumDriverInfo 得到的DriverDate有誤 RRS feed

  • 問題

  • Dear All

    我在開發一個列出全部裝置Driver資訊的Lib

    使用SetupDiEnumDriverInfo的Method

    印出來的資料也都正確,當我以為安然過去後…發現在win8上有些Device的Driver Date 跟 我印出來的竟然差一天!

    ex:

    裝置管理員->DriverDate:20/6/2011      我印出來的 19/6/2011
    inf file->DriverDate:20/6/2011

    很謉異情況… 大部份都是正確的,只有少數的裝置會這樣… 目前發現的有nVidia VGA, TouchPad (似乎都是3rd praty device)

    去看了該裝置的inf檔,DriverDate這一欄都是正確的(20/6/2011),

    msdn表示SetupDiEnumDriverInfo中的SP_DRVINFO_DATA 是 From the DriverVer entry in the INF file

    不知道為何會有這誤差… 煩請各位幫忙找蟲了

    Lib

    1        if (!PInvoke.SetupDiBuildDriverInfoList(
                   deviceInfoSet, 
                   ref deviceInfoData, 
                   PInvoke.SPDIT_COMPATDRIVER)) 
    2       { 
    3           throw new Exception("Cannot Build Driver Info List"); 
    4       } 
    5	PInvoke.SP_DRVINFO_DATA driverData = new PInvoke.SP_DRVINFO_DATA(); 
    6	driverData.cbSize = (uint)Marshal.SizeOf(typeof(PInvoke.SP_DRVINFO_DATA)); 
    7	int i = 0; 
    8	while (PInvoke.SetupDiEnumDriverInfo(deviceInfoSet, ref deviceInfoData, PInvoke.SPDIT_COMPATDRIVER, i, ref driverData)) 
    9	{ 
    10	     i++; 
    11     } 
    12	long longTypeTime = (((long)driverData.DriverDate.dwHighDateTime) << 32) + driverData.DriverDate.dwLowDateTime; 
    13    DateTime date = DateTime.FromFileTime(longTypeTime); 
    14    drvString[(int)CommonEnum.DeviceProperty.DriverDate] = date.ToShortDateString(); 
    1	[DllImport("setupapi.dll", SetLastError = true)] 
    2	public static extern bool SetupDiBuildDriverInfoList(IntPtr DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, int DriverType); 
    3	 
    4	[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Unicode)] 
    5	public static extern bool SetupDiEnumDriverInfo( 
    6	    IntPtr DeviceInfoSet,  
    7	    ref SP_DEVINFO_DATA DeviceInfoData,  
    8	    int DriverType,  
    9	    int MemberIndex,                                          
    10	    ref SP_DRVINFO_DATA DriverInfoData); 
    11	 
    12	public struct SP_DRVINFO_DATA 
    13	{ 
    14	    public uint cbSize; 
    15	    public uint DriverType; 
    16	    public IntPtr Reserved; 
    17	    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 
    18	    public string Description; 
    19	    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 
    20	    public string MfgName; 
    21	    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 
    22	    public string ProviderName; 
    23	    public System.Runtime.InteropServices.ComTypes.FILETIME DriverDate; 
    24	    public ulong DriverVersion; 
    25	} 


    2013年4月9日 上午 05:38

解答

所有回覆