0

So I am trying to make a 'create shortcut' script to generate a link on my users desktop to take them directly to the "Add Printer Wizard" in Windows 10. Programatically speaking, I am pretty sure it is not possible but it is a directive from above. When the script runs, the Arguments field get dropped.

UPDATE

I can create this manually, but not programatically.

Help Me StackOverFlow ... You're our only hope

$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()

I feel stupid asking, but can anyone see what I am missing?

Community
  • 1
  • 1
  • [`#requires -RunAsAdministrator`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires) – JosefZ Sep 18 '19 at 19:54
  • I was planning to make sure that it was running in an Administrative Context, but good catch! Thanks!!! – Cortland Guse Sep 19 '19 at 15:54

1 Answers1

0

If you simply want to trigger the Add Printer Driver Wizard, here's the fixed version of your code (the arguments are differents, ref: https://learn.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()
P-L
  • 523
  • 4
  • 14
  • The code was exhibiting the same issue until I ran it in a clean test environment. Works perfectly! Thanks for the link as well, I am using it to spawn some all-new script processes. – Cortland Guse Sep 19 '19 at 17:01