无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
查看: 14155|回复: 12

[求助] 如何用命令行方式安装驱动

[复制链接]
发表于 2020-5-20 22:16:05 来自手机 | 显示全部楼层 |阅读模式
需要详细一点,参数……

注意:inf文件里没有defaultinstall这一节。
发表于 2020-5-20 22:31:32 | 显示全部楼层
如果inf文件不规范,任何命令无法安装。
回复

使用道具 举报

发表于 2020-5-21 09:02:34 | 显示全部楼层
其实有第三方小程序可以直接去安装sys文件,而不需要inf
回复

使用道具 举报

发表于 2020-5-21 09:06:31 | 显示全部楼层
回复

使用道具 举报

发表于 2020-5-21 09:49:22 来自手机 | 显示全部楼层
命令安装可以做到,但是马上起效并不容易。就是你可以给系统添加,但下次开机并不会直接使用,而需要手动执行一个过程,再次重启才能开始使用。
回复

使用道具 举报

 楼主| 发表于 2020-5-21 17:12:03 来自手机 | 显示全部楼层
谢谢各位的讨论及帮助。
回复

使用道具 举报

 楼主| 发表于 2020-5-21 17:15:19 来自手机 | 显示全部楼层
sorry我没有把事情的背景说清楚。我是在绿化gilisoft ramdisk这个软件时遇到了困难。只有在安装了正确的驱动后,软件才能正常启动,否则会提示“加载磁盘错误”之类的。我试过用
回复

使用道具 举报

 楼主| 发表于 2020-5-21 17:31:00 来自手机 | 显示全部楼层
inno setup和相关的反编译安装的工具试图查出安装程序是做了些啥,怎么做的,但没有发现有帮助的内容。用反安装的工具监视并分析后,发现它给系统安装了ramdisk.sys的驱动。但不知道它是怎么安装的。在手动安装(右键点击inf文件在弹出的菜单上点“安装”,我是在win10系统里操作的),安装驱动成功后软件可以正常启动。这就需要我解决用命令行给系统安装驱动这个问题。我查过一些资料,有用 rundll32命令安装,也有其它的,但不清楚各参数如何用,反正安装是不成功的。我查的资料里说,inf文件里如果有Defaultinstall这节才能套用,如果有 manufacturer这节就不会有Defaultinstall这节。可这个inf里就是这样的情况。只有manufacturer。这种inf哪一节是安装的节(可调用的参数)呢
回复

使用道具 举报

发表于 2020-8-4 12:19:21 | 显示全部楼层
windowsddk中有一个叫dpinst的程序,可以安装inf,sys这类驱动,不知道是否对你有帮助。
回复

使用道具 举报

 楼主| 发表于 2021-2-3 21:05:41 | 显示全部楼层
DEVCON是设备管理器的命令行版本,可以查看其帮助:

C:\Users\hhu\Desktop\WME\Drivers>devcon /?
Device Console Help:
devcon [-r] [-m:\\<machine>] <command> [<arg>...]
-r if specified will reboot machine after command is complete, if needed.
<machine> is name of target machine.
<command> is command to perform (see below).
<arg>... is one or more arguments if required by command.
For help on a specific command, type: devcon help <command>
classfilter          Allows modification of class filters.
classes              List all device setup classes.
disable              Disable devices that match the specific hardware or instanc
e ID.
driverfiles          List driver files installed for devices.
drivernodes          Lists all the driver nodes of devices.
enable               Enable devices that match the specific hardware or instance
ID.
find                 Find devices that match the specific hardware or instance I
D.
findall              Find devices including those that are not present.
help                 Display this information.
hwids                Lists hardware ID's of devices.
install              Manually install a device.
listclass            List all devices for a setup class.
reboot               Reboot local machine.
remove               Remove devices that match the specific hardware or instance
ID.
rescan               Scan for new hardware.
resources            Lists hardware resources of devices.
restart              Restart devices that match the specific hardware or instanc
e ID.
sethwid              Modify Hardware ID's of listed root-enumerated devices.
stack                Lists expected driver stack of devices.
status               List running status of devices.
update               Manually update a device.
updateni             Manually update a device (non interactive).


    为了安装这个虚拟硬件,只需要运行以下命令行:

devcon install xpvcom.inf "root\XPVCOM"
devcon rescan

    你要问“root\XPVCOM”设备描述符哪里来的?打开inf文件就能看到

……

[Standard]
;
;

%XPVCOM.DeviceDesc%=XPVCOM_Device, root\XPVCOM
……


    命令行安装一个驱动,就这么简单。
回复

使用道具 举报

 楼主| 发表于 2021-2-3 21:08:30 | 显示全部楼层
win7(64位) or win8下(64位),有硬件驱动文件(inf,sys,dll),希望通过命令行方式安装安装驱动程序。
已经试过 **:
rundll32 SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 xx.inf 方式,失败
rundll32 SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 xx.inf 方式,失败
InfDefaultInstall.exe 方法,失败
用以上方法安装无任何提示,但注册表没有写入相关信息,sys和dll也没有被拷贝到相应目录。
devcon 方法,失败(提示错误)
**注:在设备管理中通过更新驱动程序方式可以成功

回答:命令行有没有管理员权限。win8点开始按钮位置,右键,命令行(管理员),然后运行
回复

使用道具 举报

 楼主| 发表于 2021-2-3 21:09:28 | 显示全部楼层
如果想在打包时支持自动安装驱动程序,有很多种办法。这里介绍使用DPInst.exe安装inf驱动的办法。

一、Driver Install Frameworks 工具简介
Driver Install Frameworks (DIFx) 是 Microsoft 在驱动程序安装技术和工具创新方面的最新计划,该创新从将即插即用融入到 Windows 95 开始。Driver Install Frameworks 计划的目标是提供基础结构和工具来使设备和驱动程序的安装更加简单流畅。
用户会发现驱动程序和设备诊断更加简单,而且能够在必要时卸载或回滚驱动程序。供应商能够更容易地创建合格的驱动程序包、集成增值软件,以及利用标准的 Windows 机制和工具来提升安装体验。确保驱动程序包的正确和安全也很重要。DIFx 工具设计用于支持 Microsoft Windows Vista 和 Microsoft Windows Server 2008 的新的设备安装体系结构,确保驱动程序安装包的操作不会与其他设备安装、应用程序或 Windows 组件发生冲突,确保已安装的任何驱动程序能够在发生问题时彻底回滚或卸载。
二、DPInst命令行参数详解
DPInst.exe: 安装和卸载驱动程序
缺省情况下,该工具搜索当前目录并安装所有找到的驱动程序
用法: DPInst.exe [/U INF-file] [/S | /Q] [/LM] [/P] [/F] [/SH] [/SA] [/A] [/PATH Path] [/EL] [/L LanguageID] [/C] [/D] [/LogTitle Title] [/SW] [/? | /h | /help]

/U INF-file:到.INF文件的路径
/S | /Q:以安静模式卸载一个驱动程序(.INF文件),不显示设备安装向导,阻止操作系统弹出任何对话框
/LM:选择遗产代码模式(进行安装),允许安装无签名的驱动程序和文件不完整的驱动程序。这些驱动程序将无法在最新版本的Windows操作系统上安装
/P:如果要安装的驱动程序不比已安装的好,提示用户
/F:要安装的驱动程序不比已安装的好时,强制(执行当前的)安装(过程)
/SH:扫描硬盘,仅为已存在的设备安装驱动程序。(该选项)仅对即插即用(设备的)驱动(程序)有效
/SA:在 添加/删除程序 (列表)中不显示当前安装的驱动程序
/A:全部安装 或 全不安装
/PATH Path:在指定的路径下搜索驱动程序
/EL:支持所有在.XML文件中未明确列出的语言
/L LanguageID:在所有的用户接口(UI)中使用指定的语言。在 本地化测试 时很有用
/SE:不显示“最终用户许可协议”
/C:将登陆信息输出到控制台(仅在 Windows XP或以上 操作系统上可用)
/D:卸载时删除驱动程序的二进制代码
/SW:不显示设备安装向导,操作系统任然可以弹出对话框
/? | /h | /help:显示此 帮助(信息)

三、可到网上下载32位和64位版本的DPInst使用:
http://download.csdn.net/detail/shuaihj/5618903
四、在INNO中的安装inf驱动的脚本是:
[Run]
      ; 安装驱动程序
      Filename: "{sys}\dpinst64"; Parameters: "/path ""{app}\drivers\UsbDriver_x64"" /sw /se"; Check: Is64BitInstallMode
      Filename: "{sys}\dpinst32"; Parameters: "/path ""{app}\drivers\UsbDriver_x86"" /sw /se"; Check: not Is64BitInstallMode
回复

使用道具 举报

 楼主| 发表于 2021-2-3 21:15:44 | 显示全部楼层
操作系统:Windows Server 2016 R2

我有一个RAMDisk驱动程序,可以通过“添加旧版硬件向导”(hdwwiz.exe)成功安装。 从devcon hwids *的输出中,可以看到该设备如下。

ROOT\UNKNOWN\0000
    Name: RAMDrive [ QSoft ] Enterprise (x64)
    Hardware IDs:
        ramdriv
但是,我需要通过Ansible完成安装,因此无法使用hdwwiz.exe 。 必须通过命令行完成,而无需交互。

我尝试了几种方法,但没有一种有效。

方法一:DevCon.exe(Windows设备控制台)

C:\Ramdisk64_inst>devcon.exe install RAMDriv.inf ramdriv

Device node created. Install is complete when drivers are installed...
Updating drivers for ramdriv from C:\Ramdisk64_inst\RAMDriv.inf.
devcon.exe failed.

C:\Ramdisk64_inst>devcon.exe install RAMDriv.inf ROOT\UNKNOWN\0000

Device node created. Install is complete when drivers are installed...
Updating drivers for ROOT\UNKNOWN\0000 from C:\Ramdisk64_inst\RAMDriv.inf.
devcon.exe failed.
这是C:\\Windows\\INF\\setupapi.dev.log的日志

>>>  [Device Install (UpdateDriverForPlugAndPlayDevices) - ramdriv]
>>>  Section start 2018/12/20 07:10:35.670
      cmd: C:\Ramdisk64_inst\devcon.exe  install C:\Ramdisk64_inst\RAMDriv.inf ramdriv
     ndv: INF path: C:\Ramdisk64_inst\RAMDriv.inf
     ndv: Install flags: 0x00000001
!    ndv: Unable to find any matching devices.
<<<  Section end 2018/12/20 07:10:35.717
<<<  [Exit status: FAILURE(0xe000020b)]


>>>  [Device Install (UpdateDriverForPlugAndPlayDevices) - ROOT\UNKNOWN\0000]
>>>  Section start 2018/12/20 07:11:50.687
      cmd: devcon.exe  install RAMDriv.inf ROOT\UNKNOWN\0000
     ndv: INF path: C:\Ramdisk64_inst\RAMDriv.inf
     ndv: Install flags: 0x00000001
!    ndv: Unable to find any matching devices.
<<<  Section end 2018/12/20 07:11:50.734
<<<  [Exit status: FAILURE(0xe000020b)]
方法2:DPInst.exe(驱动程序包安装程序)

C:\Ramdisk64_inst>dpinst.exe /PATH C:\Ramdisk64_inst /Q /C /LM

INFO:   Option set: dumping log info to console.
INFO:   Current working directory: 'C:\Ramdisk64_inst'
INFO:   Running on path 'C:\Ramdisk64_inst'
INFO:   No valid 'dpinst.xml' file provided.
INFO:   Install option set: Running in quiet mode. Suppressing Wizard and OS popups.
INFO:   Install option set: legacy mode on.
INFO:   Found driver package: 'C:\Ramdisk64_inst\RAMDriv.inf'.
INFO:   Preinstalling 'c:\ramdisk64_inst\ramdriv.inf' ...
INFO:   ENTER:  DriverPackagePreinstallW
INFO:   Driver package is already preinstalled 'c:\ramdisk64_inst\ramdriv.inf'.
SUCCESS:c:\ramdisk64_inst\ramdriv.inf is preinstalled.
INFO:   RETURN: DriverPackagePreinstallW  (0xB7)
INFO:   ENTER:  DriverPackageGetPathW
INFO:   RETURN: DriverPackageGetPathW  (0x0)
INFO:   ENTER:  DriverPackageInstallW
WARNING:DRIVER_PACKAGE_LEGACY_MODE flag set but not supported on Plug and Play driver on VISTA. Flag will be ignored.
INFO:   Installing INF file 'c:\ramdisk64_inst\ramdriv.inf' (Plug and Play).
INFO:   Looking for Model Section [DiskDevice.NTamd64]...
INFO:   No matching devices found in INF "C:\Windows\System32\DriverStore\FileRepository\ramdriv.inf_amd64_fcc99ac0622d865b\ramdriv.inf" on the Machine.
INFO:   No drivers installed. No devices found that match driver(s) contained in 'C:\Windows\System32\DriverStore\FileRepository\ramdriv.inf_amd64_fcc99ac0622d865b\ramdriv.inf'.
INFO:   RETURN: DriverPackageInstallW  (0xE000020B)
INFO:   No matching device was found for 'c:\ramdisk64_inst\ramdriv.inf'. Driver will be installed when plugged in.
INFO:   Returning with code 0x100
方法3:rundll32调用SetupAPI

C:\Ramdisk64_inst>rundll32.exe setupapi.dll,InstallHinfSection DiskInstall 128 C:\Ramdisk64_inst\RAMDriv.inf
它结束没有任何错误,但是未安装驱动程序。

方法4:PnPUtil

C:\Ramdisk64_inst>pnputil.exe /add-driver C:\Ramdisk64_inst\RAMDriv.inf /install /subdirs /restart

Microsoft PnP Utility

Adding driver package:  RAMDriv.inf
Driver package added successfully.
Published Name:         oem7.inf
Driver package installed on matching devices.

Total driver packages:  1
Added driver packages:  1
成功,但实际上未安装驱动程序。

它们都不起作用。 DpInst.exe表示No matching devices found in INF ,DevCon.exe表示Unable to find any matching devices 。 似乎是同样的原因。

但是,驱动程序可以手动与hdwwiz.exe一起安装,有人知道hdwwiz.exe的秘密是什么吗?



旧版驱动程序无法与pnputil一起安装,而必须使用LaunchINFSectionEx-Call

我测试了以下内容,并且可以与Windows 2000到Windows 10、2012R2、2016、2019的多种驱动程序一起使用。

rundll32.exe advpack.dll,LaunchINFSectionEx ykmd.inf,Yubico64_Install.NT,,4,N
注意使用正确的部分

没有[DefaultInstall] -Section时,必须使用inf-File的正确部分 。 这在大多数答案中都没有。 在驱动程序inf文件中查找它,并使用正确的部分 (在我的示例中为“ Yubico64_Install.NT”)。 使用错误的部分不会提示错误。 在我的示例中,我使用“安静”模式,无UI(4)和“从不重启”(N)以通过GPO自动安装驱动程序。 所有选项均在此处详细记录:

https://docs.microsoft.com/en-us ... tform-apis/aa768006(v%3Dvs.85)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-3-28 22:42

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表