Extract Icon from Windows .lnk (shortcut) file

后端 未结 6 891
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 13:36

I need to extract the icon from a windows shortcut (.lnk) file (or find the icon file, if it\'s just pointed to by the shortcut).

I\'m not asking about extracting ic

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 14:15

    Using the Shell32 method of acessing links:

    String lnkPath = @"C:\Users\PriceR\Desktop\Microsoft Word 2010.lnk";
    //--- run microsoft word
    var shl = new Shell32.Shell();         // Move this to class scope
    lnkPath = System.IO.Path.GetFullPath(lnkPath);
    var dir = shl.NameSpace(System.IO.Path.GetDirectoryName(lnkPath));
    var itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath));
    var lnk = (Shell32.ShellLinkObject)itm.GetLink;
    //lnk.GetIconLocation(out strIcon);
    String strIcon;
    lnk.GetIconLocation(out strIcon);
    Icon awIcon = Icon.ExtractAssociatedIcon(strIcon);
    this.button1.Text = "";
    this.button1.Image = awIcon.ToBitmap();
    

提交回复
热议问题