如何创建开始菜单快捷方式 [英] How to create start menu shortcut
本文介绍了如何创建开始菜单快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建自定义安装程序。如何在开始菜单中为可执行文件创建快捷方式?到目前为止,这是我要提出的:
I am building a custom installer. How can I create a shortcut to an executable in the start menu? This is what I've come up with so far:
string pathToExe = @"C:\Program Files (x86)\TestApp\TestApp.exe";
string commonStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
string appStartMenuPath = Path.Combine(commonStartMenuPath, "Programs", "TestApp");
// TODO: create shortcut in appStartMenuPath
中创建快捷方式我瞄准的是Windows 7。 p>
I'm targeting Windows 7.
推荐答案
使用Windows脚本宿主(确保在引用> COM选项卡下,添加对Windows脚本宿主对象模型的引用):
Using the Windows Script Host (make sure to add a reference to the Windows Script Host Object Model, under References > COM tab):
using IWshRuntimeLibrary;
private static void AddShortcut()
{
string pathToExe = @"C:\Program Files (x86)\TestApp\TestApp.exe";
string commonStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
string appStartMenuPath = Path.Combine(commonStartMenuPath, "Programs", "TestApp");
if (!Directory.Exists(appStartMenuPath))
Directory.CreateDirectory(appStartMenuPath);
string shortcutLocation = Path.Combine(appStartMenuPath, "Shortcut to Test App" + ".lnk");
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
shortcut.Description = "Test App Description";
//shortcut.IconLocation = @"C:\Program Files (x86)\TestApp\TestApp.ico"; //uncomment to set the icon of the shortcut
shortcut.TargetPath = pathToExe;
shortcut.Save();
}
这篇关于如何创建开始菜单快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文