使用 Powershell 创建将参数传递给 shell32.dll 的快捷方式



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

更新

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

帮我堆栈溢出...您是我们唯一的希望

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

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

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

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

最新更新