2019-8-31-C#-通过编程的方法在桌面创建回收站快捷方式

title author date CreateTime categories
C# 通过编程的方法在桌面创建回收站快捷方式
lindexi
2019-08-31 16:55:58 +0800
2019-3-19 9:12:4 +0800
C#

基本所有的桌面都会存在回收站快捷方式,如果想要多创建几个快捷方式,点开就是回收站,请看本文的方法

在引用 Windows Script Host Object Model 这个 COM 方法之后可以使用下面代码在桌面创建 Recycle Bin.lnk 快捷方式,这个快捷方式可以打开回收站

            object shDesktop = "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:WINDOWSSystem32imageres.dll";
            shortcut.TargetPath = "::{645ff040-5081-101b-9f08-00aa002f954e}";
            shortcut.Save();

参见 使用 C# 代码创建快捷方式文件 - walterlv

C# 如何引用 WshShell 类

c# - Programmatically create a shortcut to the recycle bin or other special folders - Stack Overflow

原文地址:https://www.cnblogs.com/lindexi/p/12085688.html