0

There are various questions and answers on SO explaining how to create a shortcut to the printer queue of a printer using powershell. They all use a shortcut destination like this: C:\Windows\System32\rundll32.exe printui.dll,PrintUIEntry /n Printername.

However, the shortcuts created like this do not have the right-click options like Scan which are visible when right-clicking the printer on the printer & devices page in the control panel. Right-clicking the printer on the Devices and Printers page reveals a Create Shortcut option, which creates a shortcut which has the same right-click options as the original item. (Dragging the printer to the desired destination folder works too)

The properties pages of the shortcuts created a) with powershell b) with the Create shortcut option also look quite different: enter image description here

Thus, my question is: How do I create a shortcut that is equivalent to the shortcut created when using the right-click option Create Shortcut on a printer on the devices and printers page with powershell?

Zulakis
  • 7,859
  • 10
  • 42
  • 67

2 Answers2

1

The correct shortcut does not point to rundll32.exe, it points to the printer in the shell namespace. This target is an item id list, not a filesystem path.

I don't know the native way to do this in Powershell. With P/invoke it would be SHParseDisplayName + IShellLink::SetIDList.

You would probably want to go the reverse way first; on a correct link, get its id list and call SHGetNameFromIDList(...,SIGDN_DESKTOPABSOLUTEPARSING,...). The returned string would look something like ::{GUIDHERE}\::{ANOTHERGUID}\MyPrinterName.

Anders
  • 97,548
  • 12
  • 110
  • 164
1

Thanks to Anders for bringing me onto the right track.

You can achieve it like this:

Get a list of all devices and printers:

$shell = New-Object -ComObject Shell.Application
$devices_and_printers = $shell.namespace("::{26EE0668-A00A-44D7-9371-BEB064C98683}\2\::{A8A91A66-3A7D-4424-8D24-04E180695C7A}")
$devices_and_printers.items() | select name,path

Create shortcut:

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$env:userprofile\Desktop\My Printer.lnk")
$Shortcut.TargetPath = ($devices_and_printers.items() | where { $_.name -eq "My Printer Name" }).Path
$Shortcut.Save()
Zulakis
  • 7,859
  • 10
  • 42
  • 67