5

I want to create an internet shortcut (url file) with a custom icon on the desktop. To create the shortcut, I currently use:

    private void CreateShortcut(string name, string url)
    {
        string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

        using (StreamWriter writer = new StreamWriter(deskDir + "\\" + name + ".url"))
        {
            writer.WriteLine("[InternetShortcut]");
            writer.WriteLine("URL=" + url);
            writer.Flush();
        }
    }

But this code does not set a custom icon. How would I set the icon?

msbg
  • 4,852
  • 11
  • 44
  • 73

1 Answers1

10

Set IconIndex and IconFile parameters:

[InternetShortcut]
URL=<url>
IconIndex=0
IconFile=<path to custom icon icon file>
max
  • 33,369
  • 7
  • 73
  • 84