c# 创建快捷方式并添加到开始菜单程序目录
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);//or Environment.GetFolderPath(Environment.SpecialFolder.Programs);
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();
}
例子2:
public static void CreateStartMenuShortcut() { string programs_path = Environment.GetFolderPath(Environment.SpecialFolder.Programs); string shortcutFolder = Path.Combine(programs_path, @"MorganTechSpaceSampleApp"); if (!Directory.Exists(shortcutFolder)) { Directory.CreateDirectory(shortcutFolder); } WshShellClass shellClass = new WshShellClass(); //Create First Shortcut for Application Settings string settingsLink = Path.Combine(shortcutFolder, "Settings.lnk"); IWshShortcut shortcut = (IWshShortcut)shellClass.CreateShortcut(settingsLink); shortcut.TargetPath = @"C:\Program FilesMorganTechSpaceMyAppSettings.exe"; shortcut.IconLocation = @"C:\Program FilesMorganTechSpacesettings.ico"; shortcut.Arguments = "arg1 arg2"; shortcut.Description = "Click to edit MorganApp settings"; shortcut.Save(); //Create Second Shortcut for Uninstall Setup string uninstallLink = Path.Combine(shortcutFolder, "Uninstall.lnk"); shortcut = (IWshShortcut)shellClass.CreateShortcut(uninstallLink); shortcut.TargetPath = @"C:\Program FilesMorganTechSpaceSetup.exe"; shortcut.IconLocation = @"C:\Program FilesMorganTechSpaceuninstall.ico"; shortcut.Arguments = "u"; shortcut.Save(); }
fffffffffffffffff
test red font.