2008-12-05 17 views
6

मुझे विंडोज शॉर्टकट (.lnk) फ़ाइल से आइकन निकालने की आवश्यकता है (या आइकन फ़ाइल ढूंढें, अगर यह शॉर्टकट द्वारा इंगित की गई है)।विंडोज .lnk (शॉर्टकट) फ़ाइल से आइकन निकालें

मैं exe's, dll's आदि से आइकन निकालने के बारे में नहीं पूछ रहा हूं। प्रश्न में शॉर्टकट बनाया गया है जब मैं एक इंस्टॉलेशन प्रोग्राम चलाता हूं। और शॉर्टकट द्वारा प्रदर्शित आइकन .exe में निहित नहीं है जो शॉर्टकट इंगित करता है। संभवतः आइकन .lnk फ़ाइल में एम्बेड किया गया है, या .lnk फ़ाइल में यह आइकन है जहां यह आइकन रहता है। लेकिन मुझे पता नहीं चला कि उपयोगिता में से कोई भी यह पता नहीं है - वे सब सिर्फ .exe पर जाते हैं।

बहुत धन्यवाद!

उत्तर

5

यह धागा data contained in a .lnk file

sSHGetFileInfoss समारोह आइकन फ़ाइल निकालने में सक्षम होना चाहिए के बारे में दिलचस्प जानकारियां प्रदान करता है।

here प्रलेखित है, और एक lnk फ़ाइल के लिए इस्तेमाल किया:

[DllImport("shell32.dll")] 
public static extern IntPtr SHGetFileInfo(
    string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, 
    uint cbSizeFileInfo, uint uFlags); 

:

Path2Link := 'C:\Stuff\TBear S Saver.lnk'; 
SHGetFileInfo(PChar(Path2Link), 0, ShInfo1, SizeOf(TSHFILEINFO), 
      SHGFI_ICON); 
// this ShInfo1.hIcon will have the Icon Handle for the Link Icon with 
// the small ShortCut arrow added} 

पहले लिंक से, आप सी #, में इस तरह के एक उपयोगिता है जहाँ आप की तरह इस समारोह घोषणा करेंगे बना सकते हैं

आप autoit script language में एक उपयोगिता भी बना सकते हैं, जहां आप इस फ़ंक्शन का उपयोग इस तरह घोषित करेंगे:

Func _ShellGetAssocIcon(Const $szFile,Const $IconFlags = 0) 
    Local $tFileInfo = DllStructCreate($tagSHFILEINFO) 
    If @error Then 
     Return SetError(1,@extended,0) 
    EndIf 

    Local $Ret = DllCall("shell32.dll","int","SHGetFileInfo","str",$szFile,"dword",0, _ 
     "ptr",DllStructGetPtr($tFileInfo),"uint",DllStructGetSize($tFileInfo),"uint",BitOr($SHGFI_ICON,$IconFlags)) 
    MsgBox(0,0,@error) 
    Return DllStructGetData($tFileInfo,"hIcon") 
EndFunc 
+1

शायद उसे संरचना आदि प्रारूप की तरह थोड़ा और जानकारी दें। लेकिन आपको मेरा वोट मिला। –

1

आप शॉर्टकट फ़ाइल प्रारूप के विवरण पर this pdf या this article देखें, स्वयं भी .lnk फ़ाइल को पार्स कर सकते हैं।

या आप this question के उत्तर में उल्लिखित शैललिंक वर्ग का उपयोग कर सकते हैं।

+0

दोनों लिंक मृत हैं। :/ – saint1729

+0

पीडीएफ लिंक यहां संग्रहित है: http://web.archive.org/web/20090408051551/http://www.i2s-lab.com/Papers/The_Windows_Shortcut_File_Format.pdf, और आलेख यहां संग्रहीत है: http://web.archive.org/web/20110817051855/http://www.stdlib.com/art6-Shortcut-File-Format-lnk.html –

0

इस के लिए कुछ और संसाधनों को जोड़ने के लिए है, क्योंकि presumeably आप नीचे बाएँ कोने में शॉर्टकट है कि आवेदन के आइकन और नहीं आइकन wan't:

1

2010 में माइक्रोसॉफ्ट ने आखिरकार एलएनके फ़ाइल प्रारूप के एक अधिकारी specification जारी किया। यह निश्चित रूप से नेट के चारों ओर तैरने वाले रिवर्स-इंजीनियर चश्मे की तुलना में अधिक सटीक और विस्तृत है।

पूर्णता के लिए, here शैल लिंक और शॉर्टकट का एमएसडीएन विवरण है।

5

acessing लिंक के Shell32 पद्धति का उपयोग करना:

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(); 
+2

http://stackoverflow.com/a/2566008 से भारी प्रतिलिपि/17034 –

0

मैं इस का उपयोग बिना आइकन पाने के लिए शॉर्टकट तीर मिनी आइकन एक छवि के रूप में यह खत्म हो गया कहा:

using IWshRuntimeLibrary;

Image ShortcutIcon = System.Drawing.Icon.ExtractAssociatedIcon(((IWshShortcut)new WshShell().CreateShortcut(File)).TargetPath).ToBitmap(); 

यदि आप इसे इसके बजाय आइकन के रूप में प्राप्त करना चाहते हैं:

Icon ShortcutIcon = System.Drawing.Icon.ExtractAssociatedIcon(((IWshShortcut)new WshShell().CreateShortcut(File)).TargetPath); 
+0

यह कोड मेरे लिए काम नहीं करता है। क्या आप विस्तार से समझा सकते हैं? –

संबंधित मुद्दे