pnputil.exe 未被识别为内部或外部命令

dee*_*rma 4 windows cmd installanywhere

当我通过命令 propmt 执行命令来安装驱动程序时:

cd C:\Windows\System32
pnputil.exe -i -a "C:\Users\Desktop\Drivers\IPEnabled_001.inf"
Run Code Online (Sandbox Code Playgroud)

它工作正常。

But if i execute the command in Installanywhere tool 
It showing the error message:
pnputil.exe is not recognized as an internal or external command
Run Code Online (Sandbox Code Playgroud)

那么你能告诉我为什么它会显示错误信息以及如何解决这个错误吗?提前致谢。

还请建议安装 inf 驱动程序的替代方法

Mof*_*ofi 6

pnputil.exe在 64 位 Windows 上只能作为 64 位应用程序使用,这意味着有%SystemRoot%\System32\pnputil.exe(x64) 但没有%SystemRoot%\SysWOW64\pnputil.exe(x86)。

使用哪个目录成为当前目录cd C:\Windows\System32取决于启动 Windows 命令解释器的应用程序架构上的 64 位 Windows cmd.exe。一个 64 位应用程序真正启动%SystemRoot%\System32\cmd.exe,但一个 32 位应用程序启动%SystemRoot%\SysWOW64\cmd.exe。原因是 Windows文件系统重定向器会将任何文件访问重定向到用于 x86 应用程序的 Windows x64 上%SystemRoot%\System32的目录%SystemRoot%\SysWOW64

最好在执行此文件之前检查此文件是否存在,此任务pnputil.exe仅在%SystemRoot%\System32独立于 Windows 体系结构的任何 Windows 上的目录中运行。

if exist %SystemRoot%\System32\pnputil.exe (
    set "SystemPath=%SystemRoot%\System32"
) else if exist %SystemRoot%\Sysnative\pnputil.exe (
    set "SystemPath=%SystemRoot%\Sysnative"
) else (
    echo ERROR: Cannot find pnputil.exe to install the driver.
    echo/
    pause
    goto :EOF
)
%SystemPath%\pnputil.exe -i -a "%USERPROFILE%\Desktop\Drivers\IPEnabled_001.inf"
Run Code Online (Sandbox Code Playgroud)

第一个IF条件适用于 32 位 Windows 上的 32 位应用程序和 64 位 Windows 上的 64 位应用程序。

对于64 位 Windows 上的 32 位应用程序,第二个IF条件为真。Sysnative是 Windows x64 上 x86 应用程序的特殊重定向器。x64 应用程序不存在SysnativeSysnative不是目录、符号链接或硬链接。因此无法使用,if exist %SystemRoot%\Sysnative因为此条件永远不会为真。需要检查重定向目录中是否存在文件,例如,if exist %SystemRoot%\Sysnative\*cmd.exe在 64 位 Windows上当前运行 32 位时才为真。

最后的ELSE分支是 true 例如在 Windows XP 上根本没有pnputil.exe

但是,不建议使用它pnputil.exe来安装驱动程序。Microsoft 免费发布驱动程序包安装程序 DPInst。有 32 位 (dpinst32.exe) 和 64 位版本 (dpinst64.exe)。使用驱动程序包安装程序可以非常轻松地安装一个或多个驱动程序。

让我们看看提供适当驱动程序(如 Intel ® )的硬件生产公司如何使用驱动程序包安装程序安装驱动程序。

驱动程序安装程序包中通常有一个目录结构,例如:

  • VISTA32
  • VISTA64
  • WIN7-x86
  • WIN7-x64
  • XPx86
  • XPx64

或者像这样的目录结构:

  • 远景
    • x86
    • x64
  • WIN7
    • x86
    • x64
  • 经验值
    • x86
    • x64

目录结构因安装程序包而异,但这并不重要,通常很容易看出哪个目录中的哪些驱动程序文件适用于哪个版本的 Windows,包括体系结构。

并且另外还有一个dpinst32.exedpinst64.exe驱动程序文件一起存储在所有子目录的父目录中,或者直接存储在包含驱动程序文件的目录中的两个驱动程序目录中。

让我们使驱动程序安装示例非常简单,并假设一个包中只有两个驱动程序文件,一个用于 Windows x86,一个用于 Windows x64。

  • WIN-32
    • dpinst32.exe
    • *。猫
    • *.dll
    • *.inf
    • *.sys
  • WIN-64
    • dpinst64.exe
    • *。猫
    • *.dll
    • *.inf
    • *.sys

通过由 32 位或 64 位执行的简单批处理文件WIN-32在 32 位 Windows 上安装 32 位驱动程序和在 64 位 Windows 上安装 64 位驱动程序的代码非常简单.WIN-64cmd.exe

set "WINARCH=64"
if "%ProgramFiles(x86)%" == "" set "WINARCH=32"
cd WIN-%WINARCH%
dpinst%WINARCH%.exe
Run Code Online (Sandbox Code Playgroud)

环境变量ProgramFiles(x86)仅存在于 Windows x64 上,这使得确定 Windows 的体系结构非常容易,另请参阅WOW64 实现细节。处理器的架构并不重要,因为在带有 AMD 64 位(兼容)处理器的 PC 上仍然可以安装 32 位 Windows。

dpinst32.exedpinst64.exe在没有任何选项的情况下启动,只需安装在当前目录中找到的所有驱动程序。