简体   繁体   English

从快捷方式启动脚本时,Powershell 找不到 PNPU​​TIL

[英]Powershell not finding PNPUTIL when script launched from shortcut

I have a Powershell script to install TCP/IP printers on Windows 10 that uses PNPUTIL to load drivers.我有一个 Powershell 脚本,用于在使用 PNPU​​TIL 加载驱动程序的 Windows 10 上安装 TCP/IP 打印机。 When the script is run from a Powershell window, everything works great.当脚本从 Powershell 窗口运行时,一切正常。

When I launch the script from a shortcut using the format当我使用格式从快捷方式启动脚本时

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -file MyScript.PS1

I get an error 'The term 'pnputil.exe' is not recognized as the name of a cmdlet, function, script file, or operable program' when PNPUTIL is called.调用 PNPU​​TIL 时,我收到错误消息“术语‘pnputil.exe’未被识别为 cmdlet、函数、脚本文件或可操作程序的名称”。 The rest of the script runs fine.脚本的其余部分运行良好。

Relevant code:相关代码:

Write-Host `n 'Installing printer driver..'
pnputil.exe /add-driver "\\myServer\HP UPD PCL 5\hpcu180t.inf"

Any ideas as to why this won't work when launched from a shortcut?关于为什么从快捷方式启动时这不起作用的任何想法?

EDIT:I tried using编辑:我尝试使用

& pnputil.exe /add-driver "\\myServer\HP UPD PCL 5\hpcu180t.inf"

as referenced in如中所述

Running CMD command in PowerShell 在 PowerShell 中运行 CMD 命令

but I still get the error.但我仍然收到错误。 I also tried我也试过

start-process pnputil.exe /add-driver "\\myServer\HP UPD PCL 5\hpcu180t.inf"

but got a similar error that pnputil.exe could not be found.但遇到类似的错误,无法找到 pnputil.exe。

Both of these options work from a Powershell prompt, but again, fail when launched from a shortcut.这两个选项都在 Powershell 提示符下工作,但同样在从快捷方式启动时失败。

Thank you in advance.先感谢您。

You're invoking a 32-bit instance of PowerShell on a 64-bit system, and that instance doesn't see pnputil.exe (by filename only).您正在64 位系统上调用 PowerShell 的32 位实例,并且该实例看不到pnputil.exe (仅按文件名)。

Instead of:代替:

 C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe -file MyScript.PS1

use:用:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file MyScript.PS1
  • Folder C:\\Windows\\SysWOW64 is where the 32-bit executables live.文件夹C:\\Windows\\SysWOW64是 32 位可执行文件所在的位置。
  • Paradoxically, for historical reasons, it is C:\\Windows\\System32 that houses the 64-bit executables.矛盾的是,由于历史原因,存放 64 位可执行文件的是C:\\Windows\\System32

If, for some reason, you do need to run a 32-bit instance of PowerShell, you can invoke pnputil.exe by its full path:如果出于某种原因,您确实需要运行 PowerShell 的 32 位实例,则可以通过其完整路径调用pnputil.exe
It only exists as a 64-bit executable in the 64-bit system folder, which 32-bit processes can access as C:\\Windows\\SysNative :它仅作为 64 位系统文件夹中的 64 位可执行文件存在,32 位进程可以作为C:\\Windows\\SysNative

C:\Windows\SysNative\pnputil.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM