2

I'm trying to open an application by using it's shortcut file in C#. right now I am able to get it's path but I Wanted to know if I can get it's icon too or not? (I mean the icon of the application which is located in it's main folder not the icon of it's shortcut) thank you.

Right Now My Code is like this:

 public static void DoSomeHeavyLifting()
    {
        string filepath = @"C:\Users\Hello\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Adobe Photoshop 2020.lnk";

        string pathOnly = filepath;
        string filenameOnly = filepath;

        Shell shell = new Shell();
        Folder folder = shell.NameSpace(pathOnly);
        FolderItem folderItem = folder.ParseName(filenameOnly);
        if (folderItem != null)
        {
            Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
      
            Console.WriteLine(link.Path);
        }

    }

as you see I can Only Have link.Path But I want it's icon too

2
  • 2
    The title and the body of the question ask for two different things. Also, which Icon? Is the Icon returned by Icon.ExtractAssociatedIcon() enough? Or do you want to extract the Jumbo sized Icon, if any? Or all Icons? Or all Icons in all available sizes?
    – Jimi
    Commented Jul 2, 2021 at 15:38
  • 1
    Show us your current code, tell us what it is doing, and then tell us what you want it to do instead. Commented Jul 2, 2021 at 15:39

1 Answer 1

3

Does this work for you?

It's pretty straightforward to use just with the file path.

private void ExtractAssociatedIconEx()
{
    Icon ico =
        Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
    this.Icon = ico;
}

Just make sure the file exists first as you will get ArgumentException if it doesn't

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.