开发者

How to create a shortcut to a printer programmatically?

开发者 https://www.devze.com 2023-04-12 18:20 出处:网络
Normally you can create a shortcut to a printer from right click menu of printer itself. Is there any other way around?

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 IWshSh开发者_如何学Goortcut 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消