public static void Create( string PathToFile, string PathToLink, string Arguments, string Description) { ShellLink.IShellLinkW shlLink = ShellLink.CreateShellLink(); Marshal.ThrowExceptionForHR(shlLink.SetDescription(Description)); Marshal.ThrowExceptionForHR(shlLink.SetPath(PathToFile)); Marshal.ThrowExceptionForHR(shlLink.SetArguments(Arguments)); ((System.Runtime.InteropServices.ComTypes.IPersistFile)shlLink).Save(PathToLink, false); }
private void CreateShortcut(string shortcut) { if (File.Exists(shortcut)) { return; } using (var link = new ShellLink()) { link.Target = _mainExecutable; link.Description = _application; link.WorkingDirectory = Path.GetDirectoryName(Path.GetDirectoryName(_mainExecutable)); link.Save(shortcut); } }
private void CreateStartMenuIcon(string path) { var startPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs"); using (ShellLink shortcut = new ShellLink()) { shortcut.Target = Path.Combine(path, "MediaCrush.exe"); shortcut.Description = "MediaCrush"; shortcut.WorkingDirectory = path; shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; shortcut.Save(Path.Combine(startPath, "MediaCrush.lnk")); } }