public static void InstallShortcut(Shortcut shortcut) { if (string.IsNullOrWhiteSpace(shortcut.ShortcutPath)) { throw new ArgumentNullException(nameof(shortcut.ShortcutPath)); } using (ShellLink shellLink = new ShellLink { TargetPath = shortcut.TargetPath, Arguments = shortcut.Arguments, Description = shortcut.Comment, WorkingDirectory = shortcut.WorkingFolder, WindowStyle = ConvertToWindowStyle(shortcut.WindowState), IconPath = shortcut.IconPath, IconIndex = 0, AppUserModelID = shortcut.AppUserModelID }) { if (shortcut.AppUserModelToastActivatorCLSID != Guid.Empty) { shellLink.AppUserModelToastActivatorCLSID = shortcut.AppUserModelToastActivatorCLSID; } shellLink.Save(shortcut.ShortcutPath); } }
public static bool ShortcutExist(Shortcut shortcut) { if (!File.Exists(shortcut.ShortcutPath)) { return(false); } using (ShellLink shellLink = new ShellLink(shortcut.ShortcutPath)) { return(IsNullEmptyOrEquals(shellLink.TargetPath, shortcut.TargetPath, StringComparison.OrdinalIgnoreCase) && IsNullEmptyOrEquals(shellLink.Arguments, shortcut.Arguments, StringComparison.Ordinal) && IsNullEmptyOrEquals(shellLink.Description, shortcut.Comment, StringComparison.Ordinal) && IsNullEmptyOrEquals(shellLink.WorkingDirectory, shortcut.WorkingFolder, StringComparison.OrdinalIgnoreCase) && (shellLink.WindowStyle == ConvertToWindowStyle(shortcut.WindowState)) && IsNullEmptyOrEquals(shellLink.IconPath, shortcut.IconPath, StringComparison.OrdinalIgnoreCase) && IsNullEmptyOrEquals(shellLink.AppUserModelID, shortcut.AppUserModelID, StringComparison.Ordinal) && ((shortcut.AppUserModelToastActivatorCLSID == Guid.Empty) || (shellLink.AppUserModelToastActivatorCLSID == shortcut.AppUserModelToastActivatorCLSID))); } }