【问题标题】:Creating a shortcut passing arguments to shell32.dll using Powershell使用 Powershell 创建将参数传递给 shell32.dll 的快捷方式
【发布时间】:2019-09-18 17:22:47
【问题描述】:

所以我正在尝试制作一个“创建快捷方式”脚本以在我的用户桌面上生成一个链接,以将他们直接带到 Windows 10 中的“添加打印机向导”。从编程上讲,我非常确定 em> 这是不可能的,但它是来自上面的指令。当脚本运行时,Arguments 字段被删除。

更新

我可以手动创建它,但不能以编程方式。

帮助我 StackOverFlow ...你是我们唯一的希望

$sArguments = "shell32.dll,SHHelpShortcuts_RunDLL PrintersFolder"
$AppLocation = "C:\Windows\System32\rundll32.exe"
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$env:PUBLIC\Desktop\UAT Devices and Printers.lnk")
$Shortcut.TargetPath = $AppLocation
$Shortcut.Arguments = $sArguments
$Shortcut.IconLocation = "devicecenter.dll,0"
$Shortcut.Description ="UAT Devices and Printers"
$Shortcut.WorkingDirectory ="C:\Windows\System32"
$Shortcut.Save()

我觉得这个问题很愚蠢,但谁能看到我错过了什么?

【问题讨论】:

标签: powershell arguments parameter-passing rundll32


【解决方案1】:

如果您只是想触发Add Printer Driver Wizard,这里是您的代码的固定版本(参数不同,参考:https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/rundll32-printui):

$sArguments = "printui.dll,PrintUIEntry /id"
$AppLocation = "C:\Windows\System32\rundll32.exe"
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$env:PUBLIC\Desktop\UAT Devices and Printers.lnk")
$Shortcut.TargetPath = $AppLocation
$Shortcut.Arguments = $sArguments
$Shortcut.IconLocation = "devicecenter.dll,0"
$Shortcut.Description ="UAT Devices and Printers"
$Shortcut.WorkingDirectory ="C:\Windows\System32"
$Shortcut.Save()

【讨论】:

  • 在我在干净的测试环境中运行之前,代码一直存在同样的问题。完美运行!也感谢您的链接,我正在使用它来生成一些全新的脚本进程。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-30
  • 1970-01-01
  • 2018-10-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多