使用 Windows 批处理文件安装 .inf 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/619604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:07:07  来源:igfitidea点击:

Installing a .inf file using a windows batch file

windows

提问by Terry

When you right click on a .inf file you have an option to "Install". I want to install a .inf file from the command line using a batch file. What is the "right" way to do this?

当您右键单击 .inf 文件时,您可以选择“安装”。我想使用批处理文件从命令行安装 .inf 文件。这样做的“正确”方法是什么?

Thanks!

谢谢!

[edit] I should clarify that I am trying to run this on Windows XP (and not Vista). Though I appriciate (and up-voted) the below answer mentioning InfDefaultInstall.exe, I believe that program was not shipped with XP.

[编辑] 我应该澄清一下,我试图在 Windows XP(而不是 Vista)上运行它。尽管我对以下提到 InfDefaultInstall.exe 的答案感到满意(并投了赞成票),但我相信该程序并未随 XP 一起提供。

回答by Joey

You can find the command when looking at the HKCR\inffile\shell\Install\commandregistry key. On Windows XP this is

查看HKCR\inffile\shell\Install\command注册表项时可以找到该命令。在 Windows XP 上这是

%SystemRoot%\System32\rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 %1

on Windows Vista and later this would be

在 Windows Vista 和更高版本上,这将是

%SystemRoot%\System32\InfDefaultInstall.exe "%1"

To use the batch file across several Windows versions you would need some trickery. You could use reg.exeto query for the key and try parsing the output (I didn't find a quick way of getting only the value from reg). If you know what platforms you're running on you could also hard-code the command lines and switch according to the Windows version (which would need another hack to find that out. %OS%doesn't tell you more than "Windows NT", unfortunately.).

要在多个 Windows 版本中使用批处理文件,您需要一些技巧。您可以使用reg.exe来查询键并尝试解析输出(我没有找到仅从 中获取值的快速方法reg)。如果你知道你在什么平台上运行,你也可以硬编码命令行并根据 Windows 版本进行切换(这需要另一个黑客才能找到。%OS%不幸的是,它告诉你的不仅仅是“Windows NT” .)

回答by Mick

rem tested/works

:inf
ver | findstr /il "Version 6." > nul 
if %ERRORLEVEL%==0 goto :vista

:xp
start/wait rundll32.exe setupapi,InstallHinfSection DefaultInstall 4 %_%
goto :eof
:vista
%SystemRoot%\System32\InfDefaultInstall.exe "%_%"

:eof

回答by dolmen

Should works on any Windows system that has IE 4.0+:

应该适用于任何具有 IE 4.0+ 的 Windows 系统:

RunDll32 advpack.dll,LaunchINFSection <file.inf>,DefaultInstall