zoukankan      html  css  js  c++  java
  • windows设备驱动安装指南

    高观点下的设备驱动安装(overview)

    一.windows是怎样安装设备的?

    第一步:新设备的识别

     在给一个新设备安装驱动之前,总线或集线器(hub)驱动会为连接到PC上的设备分配一个硬件ID(hardwareID)给设备。windows会根据这一系列的硬件ID匹配一个最接近设备的驱动安装包来安装驱动。

    硬件ID的格式一般由以下组成:

    · 一个特定的总线前缀,例如:PCI\,    USB

    · 设备特定的厂商标识符。例如,厂商,型号,修正标识。这些格式(包括硬件ID)依赖于总线驱动

    一个独立的硬件厂商可以为设备提供一个或者多个兼容ID,兼容ID的格式与硬件ID一样。然而,兼容ID比硬件ID更具有普适性(不依赖与特定的厂家和型号)。如果windows用这些硬件ID找不到匹配的驱动安装包,(Driver Package,一般有硬件厂商提供包含类协安装器,sys文件本身,cat数字签名文件,inf文件),那么就会用兼容ID继续查找匹配的安装包。硬件厂商可以在inf文件里面写入一个或者多个兼容ID。

    windows用这些硬件ID和兼容ID搜索匹配的驱动安装包。

    以下是具体实例:

    when a user plugs a wireless local area network (WLAN) adapter into the port of a USB hub that is attached to the computer, the following steps occur:

    1. The device is detected by the USB hub driver. Based on information that it queries from the adapter, the hub driver creates a hardware ID for the device.

      For example, the USB hub driver could create a hardware ID of USBVID_1234&PID_5678&REV_0001 for the WLAN adapter, where:

      • VID_1234 is the identifier of the vendor.
      • PID_5678 is the product, or model, identifier of the device.
      • REV_0001 is the revision identifier of the device.

      For more information about the format of USB hardware IDs, see Identifiers for USB Devices.

    2. The USB hub driver notifies the Plug and Play (PnP) manager that a new device was detected. The PnP manager queries the hub driver for all of the device's hardware IDs. The hub driver can create multiple hardware IDs for the same device.

    3. The PnP manager notifies Windows that a new device needs to be installed. As part of this notification, Windows is provided with the list of hardware IDs.

    4. Windows starts a search for a driver package that matches one of the device's hardware IDs. If Windows cannot find a matching hardware ID, it searches for a driver package that has a matching compatible ID for the device.

    第二步,给设备选择驱动

    windows根据inf文件中Models Section的硬件iD和兼容ID选择驱动程序(sys文件),以下时搜索路径:

    Search phaseWindows Server 2003, Windows XP, and Windows 2000Windows Vista and Windows Server 2008Windows 7 and later versions of Windows
    Without user interaction DevicePath Driver store

    Windows Update

    Driver store

    DevicePath

    With user interaction

    Prompt for distribution media

    Windows Update

    DevicePath

    Windows Update

    Prompt for distribution media

    Not applicable

    以下是具体实例:

     if a user plugs a wireless local area network (WLAN) adapter into a port of a USB hub on a computer that is running Windows Vista, the following steps occur:

    • After the USB hub driver creates a list of hardware IDs for the WLAN adapter, Windows first searches the driver storefor a matching driver package for the device.

    • If a matching driver package is not found, Windows starts the Found New Hardware Wizard. The wizard prompts the user and displays an option to locate and install the driver software. If the user selects the option, the wizard searches for a matching driver package from one of the following locations:

      • The Universal Naming Convention (UNC) paths that are identified by the DevicePath registry value ofHKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersion.

      • Windows Update

      • The distribution medium that the independent hardware vendor (IHV) provided for the device.

      If a driver package is found, Windows stages the package into the driver store from which the driver for the device will be installed.

    Note  Starting with Windows Vista, the operating system always installs a driver package from the driver store. If a matching driver package is found in another location, Windows first stages the package to the driver store before it installs the driver for the device.

    As another example, if a user plugs a WLAN adapter into a port of a USB hub on a computer that is running Windows 7, the following steps occur:

    • After the USB hub driver creates a hardware ID for the WLAN adapter, Windows first searches Windows Update for a matching driver package for the device. If a driver package is found, Windows stages it into the driver store from which the driver for the device will be installed.

    • If a driver package is not found, Windows searches the driver store for a matching driver package for the device.

      Windows also searches for a matching driver package that was preloaded in the locations that are identified by theDevicePath registry value. If a driver package is found, Windows stages it into the driver store from which the driver for the device will be installed.

    Note  Starting with Windows 7, the operating system performs the search for matching driver packages without requiring user interaction.

    选择驱动

    windows会找出与新设备(新插入的)匹配的一个或者多个驱动安装包。如果只发现一个安装包,那么就按照安装包里面的inf文件进行安装驱动。如果发现多个安装包,windows会给这些安装进行一个排序,哪个的排名值最低,就安装哪个驱动。如果多个驱动安装包有符合最低值,windows会按照以下标准选择一个最佳驱动来安装:

    rule 1:

    无论驱动是否带数字签名认证,从windows vista开始,windows会选择带数字签名的驱动进行安装。

    rule 2:

    驱动的日期和版本,定义在inf文件中。

    第三步:给设备安装驱动

    windows为设备选择好最佳驱动后,它会按以下方式保存一些设备和驱动的相关信息:

    · 多个同型号和同版本的设备连接到电脑,每个设备会被分配一个设备实例(可以理解成物理设备的抽象)

    windows会为每个设备实例分配一个设备节点(PNP管理器创建的节点,这些节点形成设备树,每个节点都包含设备栈等信息)。

    windows会为一个驱动分配一个驱动节点(其实就是存储了一些inf文件的一些信息,协安装器,注册表等)。

     

    设备和驱动都实例化好了以后,windows就开始安装驱动了:

    1.直接依赖于inf文件信息的执行动作

    · 根据inf文件的信息拷贝在硬盘上的驱动的二进制文件(SYS文件)和一些关联文件。

    · 根据inf文件的信息注册指定设备的协安装器

    协安装器是一个win32 DLL形式的文件,以辅助安装。协安装器一般会在SYSTEM注册表下写入一些附加信息或者执行一些inf文件不能处理的安装任务。协安装器也能提供安装完成的页面向导(从VISTA开始)或安装完成后的行为(获取对设备请求的操作参数等)。

    2.windows会根据inf文件Version Section里面的ClassGUID和Class确定特定设备安装类。为了完成安装,被安装和配置好的设备以同一种类别被归属到相应的设备安装类中。如果有需要的话,设备安装类指定了设备的类安装器和类协安装器。如果设备不属于系统定义的设备安装类,设备厂商就要创建在驱动安装包里面提供一个类安装器,这个类安装器会创建一个新的设备安装类。

    3.驱动安装包的文件拷贝完了和协安装器注册完了以后,windows就把控制权转移到PNP管理器,PNP管理器就开始加载驱动和启动设备了。

    4.PNP管理器会为设备加载恰当的功能驱动和可选的过滤驱动。PNP管理器会调用所请求,但还没有加载的驱动程序的Driver Entry例程。然后为每个驱动调用AddDevice例程,然后启动低层的过滤驱动,再然后是功能驱动,最后是上层的过滤驱动。PNP管理器为设备分配资源,如有需要,会发送一个IRP_MN_START_DEVICE给设备的驱动(包括过滤驱动等)

    5.如果驱动安装包提供了协安装器,windows就会发送一些DIF码给协安装器以运行附加安装过程。这些功能码执行的任务一般是设备安装前,中,后时期发生。

    以上完成了,那么设备也就安装完了,可以使用了。

    二,设备安装的组件

    设备安装过程中需要一些组件的参与才能安装。

     

     

    在上图中,没有阴影的方块是操作系统提供的组件,有阴影的方块是设备硬件厂商提供的组件。

     

    三,设备安装的一些文件

    1.inf文件------会被拷贝到inf目录下以oemXX.inf的形式命名

    2.一个或多个驱动文件(.sys文件)--------会被拷贝到Drivers目录下

    3.数字签名文件(.cat文件)--------该文件包含了驱动安装包的数字签名

    4.一个或多个协安装器-----------win32 DLL形式的方式提供

    5.其他(可选)

     

    四,设备安装类型

    1.服务器端安装

    服务器端的设备安装能被PNP管理器的用户模式组件和内核模式组件完全处理。也就是说,设备安装时发生在系统上下文时候,所以不支持用户界面互交,在此过程中,用户界面不能显示。

    只要以下条件满足,设备安装就会发生:

    1.1 设备被总线驱动发现,并通知PNP管理器

    1.2 PNP管理器发现inf文件里面与匹配设备的硬件ID

    1.3 inf文件和驱动都带数字签名了

    1.4 SetupAPI能在不需要提示用户媒体位置的情况下,定位所有的设备驱动。

    也就是说,只要预安装驱动(SetupOEMINFCopy),设备驱动就能自动安装。

    2.客户端的安装

    客户端的安装需要与用户互交,也就是安装过程发生在用户互交的上下文时候。

    以下一个或多个条件成真是,客户端的安装才会发生:

    2.1 PNP管理器不能找到包含匹配设备硬件ID的inf文件

    2.2  PNP管理器不能定位所请求的驱动文件

    2.3 inf文件和驱动文件没有经过数字签名

    2.4 SetupAPI不得不以用户界面的方式提示用户媒体位置

    2.5 类安装器和类协安装器会在安装的最后显示属性页

    2.6 设备,总线或总线驱动不支持PNP

     

    五,windows是怎样选择驱动的

    1.驱动选择过程概览

    windows会把一个驱动表示为一个驱动节点,这个节点包含了支持这设备的所有软件,例如一些服务,特定设备的协安装器和注册表。这些设备服务包含了一个功能驱动和一些上层和低层的过滤驱动。

    一些设备需要一个支持设备族的驱动(厂商提供)。然而,其他一些能被系统提供的驱动所驱动的设备支持所有的设备安装类的设备。如果windows没有发现最佳匹配驱动,它就会按排名选择一个驱动

    1.1windows怎样搜索驱动

    windows会在特定路径搜索一个设备的驱动,如果以下条件为真,windows就匹配为设备一个驱动:

    总线报告给PNP管理器的ID与inf文件里面的匹配;

    XP系统及以后的系统中,如果匹配的ID(在inf文件Models Section里面,指定了目标系统),那么设备就会在目标系统上安装;

    1.2 windows怎样对驱动进行排名

    windows会创建一个所有匹配的驱动的清单列表,然后并为每个驱动分配一个名次。每个驱动的名次值都是大于或等于0的整型值。

    从windows vista开始,windows会根据驱动是否带数字签名来排名,具体方式如下:

    如果 AllSignersEqual Group Policy  这个策略关闭了,windows会把带微软数字签名的驱动排在带Authenticode 数字签名的驱动的前面(也就是说,带微软数字签名的整形值大于Authenicode数字签名驱动的整型值)。这样的一个方式只是为了选择一个更加匹配设备的驱动。

    如果 AllSignersEqual Group Policy  这个策略打开了,windows会把所有带数字签名的驱动排在相等的位置(也就是说,名次的整型值相等)

    注意:从windows 7开始,默认AllSignersEqual Group Policy  这个策略是打开的。在vista和windows server 2008中,这个策略默认是关闭的。

    1.3windows怎样选择驱动

    windows选择一个名次值最低(整型值最低)的驱动为最佳匹配设备的驱动。

    然而,如果是多个驱动的名次值相等,那么windows会根据驱动的日期和版本选择一个驱动,驱动的日期和版本在inf文件里面指定了。windows使用以下方式来选择驱动:

    windows选择一个名次值最低(整型值最低)的驱动为最佳匹配设备的驱动。

    如果名次值相等,windows选择一个最近日期的驱动。

    如果名次值和驱动日期都相等,windows会选择一个最高版本的驱动

    windows XP SP1和之后的系统:如果排名,日期和版本都相等,那windows可以选择任意一个驱动

    windows XP和windows 2000:如果排名,日期和版本都相等,那windows可以选择任意一个驱动

    另外,值得注意的是,只限windows 2000,只有在驱动包签名之后,windows才能选择一个最近日期的驱动。否则,windows就不能使用DriverVer这个项(此项在inf文件中定义),然后就会使用 00/00/0000这种默认的日期。

    2.windows到哪里搜索驱动?

    在设备被附加到PC后,windows就会开始定位驱动安装包的位置了。windows会到许多位置下搜索驱动包,并分两步骤执行:

    没用户的互交下搜索驱动:

    当设备插入PC,windows首次会在无用户的互交的可信任的系统下定位并安装驱动:

    从windows 7开始,windows会自动从windows Update上下载匹配的驱动包(过程中不提示用户权限)。如果找到了,就把驱动包下载下来并安装到Driver Store中。(所谓的Driver Store是,从windows vista开始,Driver Store是一个第三方驱动包和微软自带驱动包的可信任的集合。操作系统把它们保存在一个硬盘上的安全位置。只有在Driver Store中的驱动包才能被安装。当驱动包被拷贝到Driver Store时,所有的驱动包相关文件都被拷贝进去了。驱动包中的文件对于设备驱动的安装都是至关重要的。inf文件必须引用到所有设备安装所要求的文件,它们才能被拷贝进Driver Store,反之,则不能拷贝进Driver Store。具体参考:http://msdn.microsoft.com/en-us/library/windows/hardware/ff544868(v=vs.85).aspx

    如果匹配的驱动包不能被下载下来,windows就会在Driver Store中搜索匹配的驱动包。这包含系统自带的驱动包,预安装好的驱动包,安装过了的驱动的驱动包。

    windows也会搜索注册表DevicePath键值指定的位置,此键为以下注册表的子键:

    HKEY_LOCAL_MACHINE
       Software
          Microsoft
             Windows
                CurrentVersion

    默认情况下,DevicePath键值为 %SystemRoot%INF 目录。

    如果驱动包在windows Update或DevicePath下被找到,windows在驱动被安装前,首先会把驱动包安装到Driver Store 。换句话说,只有被安装进Driver Store中的驱动包,驱动才能被安装。

    注意:
    对于windows server 2008和windows vista,驱动包必须被安装进Driver Store中。
    对于 Windows Server 2003, Windows XP, 和 Windows 2000,inf文件的路径必须被预先载入到DevicePath键值所指定的路径下。操作系统才能搜索到。

    这些未安装的驱动包在无用户互交的情况下,在inf文件
    INF ControlFlags section里面不能指定InteractiveInstall 这个标记。


    有用户互交下的驱动搜索:

    如果windows在无用户互交的情况下不能定位能被安装驱动包的位置,就会弹出个“发现新硬件向导”的一个对话框。这个向导就是在用户互交下定位驱动包并安装驱动的(需要管理员权限)。如下:

    • For Windows Vista and Windows Server 2008, Windows first searches for driver packages that were preloaded in the Universal Naming Convention (UNC) paths that are specified by the DevicePath registry value. If a matching driver package is found in a location that is specified by the DevicePath value, Windows first stages the driver package to thedriver store before the driver is installed. In this way, Windows always installs drivers from the driver store.

      If a matching driver package was not found and the user has enabled connecting to Windows Update to download matching drivers, the Found New Hardware Wizard accesses Windows Update to download matching drivers without displaying a wizard page. If the user has configured Windows Update to ask every time that a new device is connected, Windows displays a wizard page that prompts the user for permission to access Windows Update to download matching drivers. The Found New Hardware Wizard also searches for drivers that were preloaded in the locations that are specified by the DevicePath registry value.

    • For Windows Server 2003, Windows XP, and Windows 2000, the Found New Hardware Wizard prompts the user for a distribution medium and attempts to locate matching drivers on the medium. In addition to searching for matching drivers on the distribution medium, the Found New Hardware Wizard also searches for matching drivers that were preloaded in the locations that are specified by the DevicePath registry value.

      On Windows Server 2003 and Windows XP SP2, if the user has enabled connecting to Windows Update to locate matching drivers, the wizard also attempts to access Windows Update to download matching drivers. If the user has configured Windows Update to ask every time that a new device is connected, Windows displays a wizard page that prompts the user for permission to access Windows Update to download matching drivers. On Windows XP SP1, Windows XP, and Windows 2000, the Found New Hardware Wizard automatically attempts to access Windows Update to download matching drivers.

    注意:从windows 7开始,windows就不会在用户为管理员的互交情况下安装一个驱动了。这导致的结果就是,当设备插入PC的时候,windows再也不会弹出一个“发现新硬件向导”的对话框了。

     

     windows是怎样对驱动进行排名的?

    windows会为一个设备相匹配的驱动分配一个排名,这个排名的意思是哪个驱动最适合该设备,这个排名的值是以一个整数为代表(大于或等于0)。值越低,就越代表驱动更加匹配设备。

    这个值是个复合的值(通过各种信息源组合计算出来的),这个值依赖于驱动的签名,驱动的各种特性,还有设备的匹配类型(这些类型在device identification strings 中),这一系列的标识字符串组是在inf文件中的modules section中描述的。这个排名值是一个DWORD类型的值和一个 SP_DRVINSTALL_PARAMS结构体类型的Rank这个字段的值。     所以,排名值是一个签名的评分,一个特性的评分,一个标识符的评分的总和。这个排名值的格式为 0xSSGGTHHH,其中 S,G,T,H为4位宽,SS,GG,THHH这三个域与一个签名的评分,一个特性的评分,一个标识符的评分一一对应。以下是这三个评分的描述:

    • The signature score ranks a driver according to how a driver is signed. The signature score depends only on the value of the SS field. An unspecified signature score is represented as 0xSS0000000.

      For an overview on how Windows Vista and later versions of Windows use a driver's signature to determine how the driver is installed, see Signature Categories and Driver Installation.

    • The feature score ranks a driver based on the features that the driver supports. The feature score depends only on the value of the GG field. An unspecified feature score is represented as 0x00GG0000.

    • The identifier score ranks a driver based on the type of match between a device identification string that is reported by a device and a device identification string that is listed in an entry of an INF Models section of a driver INF file. The identifier score depends only on the value of the THHH field. An unspecified identifier score is represented as 0x0000THHH.

    For a summary of valid driver ranks and their examples, see Driver Rank Ranges and Driver Rank Example.

    For information about the system-defined constants that can be used to extract and compare rank values, see System-Defined Driver Rank Constants.

    For information about entries in the SetupAPI log that indicate the rank of a driver and the type of driver signature, seeDriver Rank Information in the SetupAPI Log.

    通过类安装器和协安装器的指定(计算)的驱动选择和排名

    其实类安装器和协安装器也可以通过处理 DIF_SELECTBESTCOMPATDRV这个请求 (或者处理 DIF_SELECTDEVICE 这个请求,这个请求是手动安装设备的时候). windows会在没有选好最佳驱动之前和建立好一堆可能(潜在匹配)的驱动的列表之后发送这些DIF请求码。当处理这些DIF请求码的时候,类安装器和协安装器就会把DNF_BAD_DRIVER 这个标记设置到这些潜在的驱动节点上(前提是如果安装器能识别出这些驱动不支持该设备)。如果DNF_BAD_DRIVER 这个标记被设置到这些潜在的驱动节点上了,那么在windows选择驱动的过程中会忽略这些被标记为DNF_BAD_DRIVER这些驱动。

    一个安装器也能通过改变这些潜在匹配的驱动排名来参与到驱动选择过程中来(前提是当安装器处理DIF_SELECTBESTCOMPATDRV (or DIF_SELECTDEVICE) 请求的时候)。然而,安装器只有一种方法能够修改一个驱动的排名就是把这个驱动的排名值设置为 0xFFFFFFFF。这个排名值意思是这个驱动能够被用于该设备,但这样的方法只是最后一种驱动选择选项(不得已之举,万般无奈才这么干)。一般情况下,安装器不应该动态修改基于类特定标准的排名值。如果安装器动态修改了驱动的排名值,安装器就会覆盖(破坏)系统基于inf文件一些信息定义的排名机制,如果安装器覆盖(破坏)了这一机制,Windows 和 Windows Update就不能够可靠的在这些潜在匹配设备的驱动列表中选择出最佳驱动。

    在windows vista和之后的版本中,根据类特定标准的指示,使用特性评分是值得推荐的做法。一个驱动的特性评分是在inf文件中的 INFDDinstall section 节中的INF FeatureScore被指定的。

    修改排名值来改变驱动选择过程的方法,类安装器和协安装器能覆盖(破坏)操作系统的整个驱动选择过程,强行为一个设备选择一个驱动。 (For more information, see DIF_SELECTBESTCOMPATDRVand DIF_SELECTDEVICE.) 然而,我们不推荐用以上的方法来做,因为在windows以后的版本中这一选择算法机制可能会被加强。当安装器直接选择一个驱动,那么操作系统的选择操作就被终止了。

    AllSignersEqual Group Policy(所有签名商等价组策略)

    从windows Vista开始,如果 AllSignersEqual Group Policy 被禁止(关闭)了,windows排名一个通过Windows signing authority (Microsoft signature)签名的驱动比以下两种都好(这个好是定义在哪个驱动更加适合设备的范畴):

    如果 AllSignersEqual Group Policy 被禁止(关闭)了,windows就会选择一个Windows signing authority签名的驱动(如果有两种 Windows signing authority 和Authenticode-signed 签名类型的驱动),然后Authenticode-signed 签名类型的驱动选择优先级又比其他的高。

    Windows signing authority 的排名值是相等的,并且它包含了以下签名类型:

    • Premium WHQL signatures and standard WHQL signatures

    • Signatures for inbox drivers

    • Windows Sustained Engineering (SE) signatures

    • A WHQL signature for a Windows version that is the same or later than the LowerLogoVersion value of the driver'sdevice setup class.

    一个网络管理员可以通过打开AllSignersEqual Group Policy来改变这种行为,这种设置就是当windows选择一个最佳驱动匹配设备的时候,windows把 Windows signing authority 和Authenticode-signed 的签名排名值都相等了。

    注意:从windows 7开始,AllSignersEqual Group Policy是默认打开的。

    以下是一个过程例子,不打算翻译了:

    For example, consider the situation where a network administrator has to configure client computers on a network to install drivers as follows:

    • A client computer should install a new driver only if the driver has an Authenticode signature that is issued by an Enterprise Certificate Authority (CA) that is created for the network. An enterprise might want to do this in order to ensure that all drivers that are installed on client computers are signed and that the only trusted signing authority other than Microsoft is the CA managed by the enterprise.

    • For signed drivers, the signature score should not be used to determine the driver that has the best rank. Only the sum of the feature score and identifier score is used to compare driver ranks. For example, if the sum of the feature score and identifier score of a new driver is lower than the corresponding sum of an inbox driver, Windows installs the new driver.

    To accomplish this, a network administrator:

    • Adds an Enterprise CA certificate to the Trusted Publisher Store of the client computers.

    • Enables the AllSignersEqual Group Policy on the client computers.

    After the network administrator configures the client computers in this manner, the administrator can sign the driver that has the Enterprise CA certificate and distribute the driver to the client computers. In this configuration, Windows on client computers will install the new driver for a device instead of a Microsoft-signed driver if the sum of the feature score and the identifier score is lower than the corresponding sum for the Microsoft-signed driver.

    Follow these steps to configure the AllSignersEqual Group Policy on Windows Vista and later versions of Windows:

    1. On the Start menu, click Run.

    2. Enter GPEdit.msc to execute the Group Policy editor, and click OK.

    3. In the left pane of the Group Policy editor, click Computer Configuration.

    4. On the Administrative Templates page, double-click System.

    5. On the System page, double-click Device Installation.

    6. Select Treat all digitally signed drivers equally in the driver ranking and selection process and then clickProperties.

    7. On the Settings tab, select Enabled (to enable the AllSignersEqual Group Policy) or Disabled (to disable theAllSignersEqual Group Policy).

    To ensure that the settings are updated on the target system, do the following:

    1. Create a desktop shortcut to Cmd.exe, right-click the Cmd.exe shortcut, and select Run as administrator.

    2. From the Command Prompt window, run the Group Policy update utility, GPUpdate.exe.

    This configuration change is made one time and applies to all subsequent driver installations on the computer until AllSignersEqual is reconfigured.

    关于驱动和设备的相关的注册表键的位置,和相关信息

    MSDN上有了:https://msdn.microsoft.com/en-us/library/windows/hardware/ff549815(v=vs.85).aspx

    下面是大概翻译整理:

    操作系统会将设备和驱动的一些相关重要信息存储进注册表中。

    注意:一般驱动程序不允许直接访问以下提到的注册表目录项和键。

    1. 设备和驱动的注册表树

    以下的注册表树对于驱动开发人员比较值得关注,在注册表的HKLM中:

    注意:HKLMSYSTEMCurrentControlSet 下的那些驱动相关的键这这里非常安全,操作系统有相关机制,来保证这些数据的安全性。但是可以用Psexec提权来删除这些键。嘿嘿。

     操作系统中的每个服务的信息都存储在HKLMSYSTEMCurrentControlSetServices  下。每个驱动都有HKLMSYSTEMCurrentControlSetServicesDriverName.这样形式的一个键。(DriverName是驱动名)。当驱动程序的DriverEntry被调用时,PNP管理器会将这个注册表路径传进驱动的入口函数的RegistryPath 这个参数中。驱动要存储驱动定义好的全局数据在这个键下。这些全局信息数据在驱动初始化的时候是有作用的。 这个键以下的一些键驱动开发人员需要注意:

    ImagePath-------- 驱动镜像文件(.sys文件)的路径,windows是通过inf文件中的 ServiceBinary 这个项来创建这个值的。详情参见:https://msdn.microsoft.com/en-us/library/windows/hardware/ff546326(v=vs.85).aspx。这个值一般为,%SystemRoot%system32DriversDriverName.sys。

    Parameters---------这个键一般存驱动特定的信息。对于一些类型的驱动,系统希望找到特定的值项。你可以再inf文件中使用AddReg这个项来为这个键下添加新值。

    Performance------- 该键会指定关于可选择性能监视的一些信息,这个键下的值,一般是驱动性能DLL的名称和该DLL导出的一些函数名,你在inf文件中可以使用AddReg这个项为这个键添加新值。

    *********************************

     HKLMSYSTEMCurrentControlSetControl 注册表树下一般包含了控制系统启动和设备配置的一些信息。以下的子键开发人员需要注意:

    Class-----包含了系统上设备安装类的信息。每个安装类都是一个子键,键名一般是安装类的GUID来命名。这些子键下一般包含类安装器,注册了的上层过滤驱动和下层过滤驱动。

    CoDeviceInstallers------ 包含了已注册好的特定类的协安装器。

    DeviceClasses--------包含了系统上设备接口的一些信息。一个设备接口类对应一个子键。这些子键下的项是注册了的设备接口类的接口实例。

    **************************************

     HKLMSYSTEMCurrentControlSetEnum 注册表树下一般包含了设备在系统上的信息。PNP管理器为每个设备创建一个子键,键名称时这样的形式:HKLMSYSTEMCurrentControlSetEnumEnumeratordeviceID. 其中deviceID就是硬件ID,Enumerator一般是设备的归类,USB,PCI,IDE等等。这些键是表明正在挂载表现在系统上的设备实例,也就是说,当设备插入,这些键才会被创建,设备被拔出,键自动删除。这些键包含了设备描述,硬件ID,兼容ID,资源需求等。

    这个Enum树一般被保留给操作系统的组件使用。驱动和应用程序不能直接访问这个树。驱动和用户模式的设备安装组件必须用系统提供的API来访问这个树并从中提取有用的信息。这些API是,驱动用这两个函数访问, IoGetDeviceProperty orIoOpenDeviceRegistryKey. 用户模式的安装组件用这两个函数访问,SetupDiGetDeviceRegistryProperty or SetupDiOpenDevRegKey

    调试驱动的时候可以用注册表编辑器查看这个树的状态。

    ******************************************

     HKLMSYSTEMCurrentControlSetHardwareProfiles 注册表树包含一些在系统上的硬件资料。

     References:

    http://zhidao.baidu.com/link?url=z33pyO3ihAxLZXcF_aAPJF6ead-DSaY2J4-paKT3-aLX8vra3E04cFws5ARhWb4LsdFNArAf_ZsixhHLMwkqTq

    http://www.codeproject.com/Articles/14500/Detecting-Hardware-Insertion-and-or-Removal

     

     

     

     

     

  • 相关阅读:
    证明LDU分解的唯一性
    SVD图片有损压缩测试
    复数系下常量乘向量的范数
    6.4.2定理证明
    证明2x2正交矩阵专置后还是正交矩阵
    百度地图 ijintui以及七牛、百度编辑器、kindeditor
    安装和使用solr
    Python验证码识别处理实例 深度学习大作业
    lucene之中文分词及其高亮显示
    Elasticsearch报警插件Watch安装以及使用
  • 原文地址:https://www.cnblogs.com/foohack/p/3437983.html
Copyright © 2011-2022 走看看