[英]Programmatically create a shortcut to the recycle bin or other special folders
我正在尝试制作一个控制台应用程序,该应用程序将创建回收站的快捷方式。
我的代码:
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
object shDesktop = (object)"Desktop";
WshShell shell = new WshShell();
string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Recycle Bin.lnk";
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "New shortcut for Recycle Bin";
shortcut.Hotkey = "Ctrl+Shift+N";
shortcut.IconLocation = @"C:\WINDOWS\System32\imageres.dll";
shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\Recycle.Bin";
shortcut.Save();
它创建一个“快捷方式”,但根本无法使用。 何时弹出消息。 我尝试打开它产生:
“ Windows正在搜索recycle.bin。要自己找到文件,请单击浏览。”
如果要创建打开特殊文件夹的快捷方式,则需要为explorer.exe创建快捷方式,并将带有双冒号前缀的适当GUID作为参数传递 :
string explorerExePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe");
shortcut.TargetPath = explorerExePath;
shortcut.Arguments = "::{645FF040-5081-101B-9F08-00AA002F954E}";
您甚至不需要提供explorer.exe作为目标,可以直接将GUID作为目标:
shortcut.TargetPath = "::{645FF040-5081-101B-9F08-00AA002F954E}";
另外,您也可以只在桌面上启用回收站的显示 。
将回收站的特殊CLSID指定为TargetPath
:
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.TargetPath = "::{645ff040-5081-101b-9f08-00aa002f954e}";
shortcut.Save();
也无需指定IconLocation
。 对于特殊文件夹,将自动选择适当的图标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.