在Windows下,几乎全部的硬件设备都须要安装驱动后才能正常工做,咱们重装系统后第一件事就是要为各设备安装好驱动,咱们能够下载官方驱动手动安装,也可让我Windows自动扫描安装,还可使用驱动精灵、电脑管家之类的工具帮咱们安装,为了发挥硬件设备最好的性能,咱们还须要及时把驱动升级到最新的版本。那么,这些工具是如何为硬件设备匹配到最佳的驱动的呢?此文就这个问题一探究竟。windows
设备都是经过hardware ID进行标识,一个设备通常有多个hardware ID和compatible ID,这些ID对设备的标识程度按照顺序依次下降,咱们能够在Windows设备管理器中查看到设备的硬件Id和兼容Id。安全
Windows下的驱动必须包含一个信息文件(INF)以进行安装,INF文本文件包含设备安装组件(device installation components)安装驱动所必需的全部信息。从INF文件中能够提取驱动匹配所需的信息:服务器
(1)驱动提供商ide
(2)驱动类型工具
(3)驱动的日期和版本性能
(4)驱动的特征值,用来衡量驱动对设备特征的支持程度ui
(5)驱动支持的操做系统版本和硬件平台spa
(6)驱动支持的设备的hardware ID和compatible ID操作系统
设备和驱动的标识匹配是指设备的hardware ID或compatible ID与驱动INF文件指定的hardware ID或compatible ID的匹配,匹配程度从高到低有如下4中类型:3d
(1)设备的hardware ID和INF的hardware ID匹配,匹配程度由设备的hardware ID的位置肯定。
(2)设备的hardware ID和INF的compatible ID匹配,匹配程度由设备的hardware ID的位置肯定。
(3)设备的compatible ID和INF的hardware ID匹配,匹配程度由设备的compatible ID的位置肯定。
(4)设备的compatible ID和INF的compatible ID匹配,匹配程度由设备的compatible ID的位置和INF的compatible ID的位置肯定,前者的优先级高。
驱动签名在驱动的匹配中也起着很关键的做用,签名的排序优先级以下:
(1)有微软签名的,包括:
* 优先级别 (Premium) 和标准级别 (Standrd) 的 WHQL 签名;
* Inbox 驱动签名 ( Signatures for inbox drivers ) ;
* 可靠驱动签名 (DRS, Driver Reliability Signature);
* SE 签名 (Windows Sustained Engineering);
* 老版本 Windows 的 WHQL 签名;
(2)有效代码签名,系统管理员能够设定安全策略来指定受信任的根证书颁发的微软代码签名证书的签名等同于微软签名;
(3)没有签名的驱动,但 INF DDInstall 中有 .nt后缀;
(4)没有签名的驱动,但 INF DDInstall 中没有 .nt后缀;
(5)没有签名或签名有问题而没法确认是否有签名的驱动。
驱动安装工具在服务器端存储了大量的驱动,对于同一个设备可能有多个驱动都合适,那么哪一个驱动再是最佳的呢?驱动匹配时就是按照以下匹配规则来选择最佳的驱动:
(1)客户端上报设备ID(hardware ID和compatible ID)的有序列表,操做系统版本,硬件平台。
(2)结合设备ID,操做系统版本,硬件平台与驱动库进行匹配,获得全部可用的驱动,若无可用的驱动,则匹配失败。
(3)选择签名最佳的驱动。
(4)选择特征最佳的驱动。
(5)选择匹配类型最佳的驱动。
(6)选择日期最新的驱动。
(7)选择版本最高的驱动。
(8)选择任一驱动。
前面提到驱动所支持的硬件等信息都是保存在INF文件中,为了能快速匹配驱动,就须要把这些信息先从INF文件中提取出来,下面就详细说明驱动信息的提取方法
1.基本信息的提取
Version section出如今INF文件最开始的位置,每个INF文件都必须包含这个section。
[Version]
Signature="signature-name"
[Class=class-name]
[ClassGuid={nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}]
[Provider=%INF-creator%]
[LayoutFile=filename.inf [,filename.inf]... ] (Windows 2000 and Windows XP)
[CatalogFile=filename.cat]
[CatalogFile.nt=unique-filename.cat]
[CatalogFile.ntx86=unique-filename.cat]
[CatalogFile.ntia64=unique-filename.cat] (Windows XP and later versions of Windows)
[CatalogFile.ntamd64=unique-filename.cat] (Windows XP and later versions of Windows)
DriverVer=mm/dd/yyyy[,w.x.y.z]
[DontReflectOffline=1] (Windows Vista and later versions of Windows)
[PnpLockDown=0|1] (Windows Vista and later versions of Windows)
[DriverPackageDisplayName=%driver-package-description%]
[DriverPackageType=PackageType]
(1)Signature必须是$Windows NT$或$Chicago$,代表在全部Windows系统下是可用的。
(2)Class指定使用该INF文件安装驱动的设备类型,关于类型的详细信息参考http://msdn.microsoft.com/en-us/library/windows/hardware/ff553426(v=vs.85).aspx
(3)Provider指定驱动的提供商,%INF-creator%在Strings section中定义。
(4)DriverVer指定驱动的日期和版本。日期是全部文件的最新日期,日期的格式为mm/dd/yyyy或mm-dd-yyyy,年必须包含4个数字,月和日必须包含2个数字;版本w.x.y.z是可选的,若是指定了版本,则w是必需的,x、y、z是可选的,w、x、y、z都是大于等于0小于65535的整数。从Windows 2000开始,INF文件在Version section中必须包含DriverVer,为整个INF指定版本信息,DDInstall sections也能够包含DriverVer,且比前者更明确,优先级更高。
(5)DriverPackageDisplayName指定驱动显示的名称,%driver-package-description%在Strings section中定义。
(6)DriverPackageType指定驱动的类型。
2.设备ID、操做系统、硬件平台、驱动特征的提取
(1)从Manufacturer section中提取全部的Models section name。
[Manufacturer]
manufacturer-identifier
[manufacturer-identifier]
[manufacturer-identifier]
...
manufacturer-identifier格式以下:
manufacturer-name |
%strkey%=models-section-name |
%strkey%=models-section-name [,TargetOSVersion] [,TargetOSVersion] ... (Windows XP and later versions of Windows)
提取manufacturer-name或models-section-name做为Models section name。
(2)TargetOSVersion提取规则
nt[Architecture][.[OSMajorVersion][.[OSMinorVersion][.[ProductType][.SuiteMask]]]]
nt 指定操做系统是基于NT的,Windows 2000及之后的版本都是基于NT的。
Architecture 指定硬件平台,若指定,必须为x86, ia64, or amd64。Windows Server 2003 SP1之前的版本,若Architecture未指定,Model section可用于任何硬件平台;Windows Server 2003 SP1及之后的版本,非x86的操做系统必须指定Architecture,x86的操做系统是可选的。
OSMinorVersion 操做系统的主版本号。
Windows version |
Major version |
Windows 8 |
6 |
Windows Server 2008 R2 |
6 |
Windows 7 |
6 |
Windows Server 2008 |
6 |
Windows Vista |
6 |
Windows Server 2003 R2 |
5 |
Windows Server 2003 |
5 |
Windows XP |
5 |
Windows 2000 |
5 |
OSMinorVersion 操做系统的子版本号。
Windows version |
Minor version |
Windows 8 |
2 |
Windows Server 2008 R2 |
1 |
Windows 7 |
1 |
Windows Server 2008 |
0 |
Windows Vista |
0 |
Windows Server 2003 R2 |
2 |
Windows Server 2003 |
2 |
Windows XP |
1 |
Windows 2000 |
0 |
ProductType 在Winnt.h文件中定义的VER_NT_xxxx,若指定,操做系统的ProductType必须与之匹配。
SuiteMask 在Winnt.h文件中定义的VER_SUITE_xxxx,若指定,操做系统的SuiteMask必须与之匹配。
TargetOSVersion的提取规则以下:
1)TargetOSVersion若指定,必须以nt开头
2)TargetOSVersion的Architecture若指定,则为指定的硬件平台;若未指定,对于Windows Server 2003 SP1之前的版本的操做系统,为任何硬件平台,对于Windows Server 2003 SP1及之后版本的操做系统,为x86硬件平台。
3)TargetOSVersion的OSMajorVersion[.OSMinorVersion]指定该section适用的操做系统的最低版本;若OSMajorVersion指定而OSMinorVersion未指定,则OSMinorVersion为0;若OSMajorVersion和OSMinorVersion都未指定,则为Windows 2000及之后全部版本。
(3)从Model section中提取操做系统版本,硬件平台,设备ID,设备描述,DDInstall section name
[models-section-name] |
[models-section-name.TargetOSVersion] (Windows XP and later versions of Windows)
device-description=install-section-name[,hw-id][,compatible-id...]
[device-description=install-section-name[,hw-id][,compatible-id]...] ...
一个models-section-name可能有多个Models section,带有不一样的TargetOSVersion,每个Models section的操做系统版本和硬件平台须要结合全部同名(名称为models-section-name. [TargetOSVersion])section肯定,规则以下:
1)按TargetOSVersion的提取规则获取每一个section的操做系统版本区间和硬件平台。
2)对于任何一个section,在同一个硬件平台下,若是任何两个同名section的版本区间存在交集,则以起始版本高的区间为准,从起始版本低的区间中移去交集。
从Model section的每一行提取一个指定的设备,device-description为设备描述,hw-id为hardware ID, compatible-id为compatible ID,install-section-name为该设备对应的DDInstall section name。
(3)从DDInstall section name提取对应某一设备的驱动特征和驱动版本。
[install-section-name] |
[install-section-name.nt] |
[install-section-name.ntx86] |
[install-section-name.ntia64] | (Windows XP and later versions of Windows)
[install-section-name.ntamd64] (Windows XP and later versions of Windows)
[DriverVer=mm/dd/yyyy[,x.y.v.z] ]
…
[FeatureScore=featurescore]... (Windows Vista and later versions of Windows)
install-section-name和install-section-name.nt适用于全部的硬件平台,其它的为指定的硬件平台。
从DriverVer中提取驱动对应某一设备在指定的硬件平台下的版本,规则同从Version section中提取DriverVer。
从FeatureScore中提取驱动对应某一设备在指定的硬件平台下的特征值,值越小代表支持的特征越佳。
3.多个INF文件
以每一个INF为单位进行提取信息,提取全部INF文件。
http://msdn.microsoft.com/en-us/library/windows/hardware/ff546228(v=vs.85).aspx