質問

Normally you can create a shortcut to a printer from right click menu of printer itself.

Is there any other way around?

I tried using IWshShortcut with following parameter as targetpath

"Control Panel\Hardware and Sound\Devices and Printers\MyPrinter"

It creates a shortcut but its not valid

Any ideas

役に立ちましたか?

解決

IWshShortcut can't create a shortcut to a printer because it supports only file system targets. To create a shortcut to a printer requires digging into the shell namespace, which is a very advanced topic. You need to get the LPITEMIDLIST for the FOLDERID_PrintersFolder, bind to that folder to get the IShellFolder, use IShellFolder::EnumObjects to enumerate the printers, decide which printer you like (perhaps by inspecting its name with IShellFolder::GetDisplayNameOf), and then use IShellLink::SetIDList to target a shell link to that printer. I gave you the magic words so you can do some searches and learn more about them, but I'm not going to try to teach the shell namespace on SO.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top