简体   繁体   中英

Making shortcut in WPF application corrupts original icon

So I have a really frustrating problem. I have a WPF application written in C# running Windows 10 (version 1703, OS Build 15063.0) that creates shortcuts for the current running executable. The problem is, when I create these, I set a different (custom) icon for the shortcuts. I didn't think this would be an issue, but the next time I run the application (from the original location) it displays the custom icon which I set for the shortcut in the taskbar. Just the taskbar. The title bar and task manager show the correct icon and title. What am I doing wrong here? At this point I think it's a Windows bug. My method for creating the shortcuts is below:

public void CreateShortcut(string name)
{
        string AppDir = GetAppDataDir();
        object shDesktop = (object)"Desktop";
        WshShell shell = new WshShell();
        string shortcutAddress = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\" + name + ".lnk";
        IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
        shortcut.Description = "Play " + name + "!!";
        shortcut.Hotkey = "Ctrl+Shift+N";
        shortcut.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        shortcut.TargetPath = Directory.GetCurrentDirectory() + "/Catapult.exe";
        shortcut.Arguments = "-play \"" + name + "\"";
        shortcut.IconLocation = AppDir + "/Games/" + name + ".ico";
        shortcut.Save();
}

It would appear that my solution is that there is no solution. In its current state, Windows does not allow you to create shortcuts with custom icons that reference an executable without messing up the existing icon for that executable. To me, this is unacceptable as I now have to use clunky code to get around this (nothing worse than that, am I right?). Microsoft needs to fix this quirky implementation in Explorer ASAP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM