powershellargumentsparameter-passingrundll32

Creating a shortcut passing arguments to shell32.dll using Powershell


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?


Solution

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