• 大小: 3KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: 其他
  • 标签: PID  VID  USB  

资源简介

获取插入的USB得PID跟VID,可以根据PID跟VID确定智能机的型号,然后安装对应的驱动。

资源截图

代码片段和文件信息

using System;
using System.Runtime.InteropServices;
using System.Text;

namespace USB 
{    
    /// 
    /// SetupApi.dll的PInvoke
    /// 

    public partial class EZUSB
    {
        #region ENUM
        [Flags]
        private enum DIGCF
        {
            DIGCF_DEFAULT = 0x00000001
            DIGCF_PRESENT = 0x00000002
            DIGCF_ALLCLASSES = 0x00000004          // 设备安装类
            DIGCF_PROFILE = 0x00000008
            DIGCF_DEVICEINTERFACE = 0x00000010     // 设备接口类
        }
        #endregion

        #region STRUCT
        [StructLayout(LayoutKind.Sequential)]
        private struct SP_DEVINFO_DATA
        {
            public static readonly SP_DEVINFO_DATA Empty = new SP_DEVINFO_DATA(Marshal.SizeOf(typeof(SP_DEVINFO_DATA)));
            public UInt32 cbSize;
            public Guid ClassGuid;
            public UInt32 DevInst;
            public IntPtr Reserved;

            private SP_DEVINFO_DATA(int size)
            {
                cbSize = (UInt32)size;
                ClassGuid = Guid.Empty;
                DevInst = 0;
                Reserved = IntPtr.Zero;
            }
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct SP_DEVICE_INTERFACE_DATA
        {
            public static readonly SP_DEVICE_INTERFACE_DATA Empty = new SP_DEVICE_INTERFACE_DATA(Marshal.SizeOf(typeof(SP_DEVICE_INTERFACE_DATA)));
            public UInt32 cbSize;
            public Guid InterfaceClassGuid;
            public UInt32 Flags;
            public UIntPtr Reserved;

            private SP_DEVICE_INTERFACE_DATA(int size)
            {
                cbSize = (uint)size;
                InterfaceClassGuid = Guid.Empty;
                Flags = 0;
                Reserved = UIntPtr.Zero;
            }
        }

        [StructLayout(LayoutKind.Sequential CharSet = CharSet.Auto)]
        private struct SP_DEVICE_INTERFACE_DETAIL_DATA
        {
            public UInt32 cbSize;
            [MarshalAs(UnmanagedType.ByValTStr SizeConst = 256)]
            public String DevicePath;
        }
        #endregion

        #region API
        #region SetupDiGetClassDevs
        [DllImport(“setupapi.dll“ CharSet = CharSet.Auto)]
        private static extern IntPtr SetupDiGetClassDevs(
            ref Guid ClassGuid
            [MarshalAs(UnmanagedType.LPTStr)] String Enumerator
            IntPtr hwndParent
            DIGCF Flags
            );        

        [DllImport(“setupapi.dll“ CharSet = CharSet.Auto)]
        private static extern IntPtr SetupDiGetClassDevs(
            IntPtr ClassGuid       // null 
            String Enumerator
            IntPtr hwndParent
            DIGCF Flags
            );
        #endregion

        #region SetupDiGetClassDevsEx
        [DllImport(“setupapi.dll“ CharSet = CharSet.Auto)]
        private static extern IntPtr SetupDiGetClassDevsEx(
          

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       7809  2013-11-27 11:44  GetUSBPidVid\SetupApi.cs

     文件       5309  2013-11-27 11:44  GetUSBPidVid\WDKVidPidQuery.cs

     目录          0  2013-11-27 11:44  GetUSBPidVid

----------- ---------  ---------- -----  ----

                13118                    3


评论

共有 条评论