在桌面上创建C#快捷方式 [英] Create shortcut on desktop C#
本文介绍了在桌面上创建C#快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要创建指向一些EXE文件的快捷方式,在桌面上,使用.NET Framework 3.5和依赖正式的Windows API。我该怎么办呢?
I want to create a shortcut pointing to some EXE file, on the desktop, using .NET Framework 3.5 and relying on an official Windows API. How can I do that?
推荐答案
使用其他选项,如热键,说明等。
With additional options such as hotkey, description etc.
首先,项目的> 添加引用的> COM的> Windows脚本宿主对象模型。
At first, Project > Add Reference > COM > Windows Script Host Object Model.
using IWshRuntimeLibrary;
private void CreateShortcut()
{
object shDesktop = (object)"Desktop";
WshShell shell = new WshShell();
string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Notepad.lnk";
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "New shortcut for a Notepad";
shortcut.Hotkey = "Ctrl+Shift+N";
shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolders.System) + @"\notepad.exe";
shortcut.Save();
}
这篇关于在桌面上创建C#快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文