By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,991 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,991 IT Pros & Developers. It's quick & easy.

How do I use COM interop to get link (.LNK) path and icon?

P: n/a
I have been trying to get access to the details of a shell link (.LNK shortcut), but no matter what I do I never get the data I need. The basic thought behind the application is to drop a file or shortcut on a form. The form will at a later point execute the program or link. I need to access both the path and the link from the shortcut

I know that this should be possible using the IShellLink interface of the Shell32.dll using COM interop. The problem is that I just don't see how I should get to it.

Does anyone out there have a clue? Nicholas Paldino suggested something similar once, but had no example

Tx!

//ecg

Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Erik,

In order to do this in what I believe is the proper way, you will have
to use a little bit of COM interop.

When a shortcut is dropped on your application, there is a data format
of the type FileName or FileNameW. These represent the path of the shortcut
that you dragged into the application.

Once you have the filename, you will have to create an object with the
CLSID of CLSID_ShellLink. You can find this value in shlobj.h. Once you
have that, you can call the static GetTypeFromCLSID method on the Type class
to get the type of this object. You can then use that Type and pass it to
the static CreateInstance method on the Activator class. This will return
an object.

You then cast this object to the UCOMIPersistFile interface. The
interface is located in the System.Runtime.InteropServices namespace. Call
the Load method, passing in the filename that you retrieved from the
dragdrop operation. This will initialize the shell link object
appropriately.

You will have to cast this object to an instance of the IShellLink
interface, which you will have to define yourself in your code. Once you
have that, you can get the details that you are looking for.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Erik Cedergren (ecgn)" <an*******@discussions.microsoft.com> wrote in
message news:51**********************************@microsof t.com...
I have been trying to get access to the details of a shell link (.LNK shortcut), but no matter what I do I never get the data I need. The basic
thought behind the application is to drop a file or shortcut on a form. The
form will at a later point execute the program or link. I need to access
both the path and the link from the shortcut.
I know that this should be possible using the IShellLink interface of the Shell32.dll using COM interop. The problem is that I just don't see how I
should get to it.
Does anyone out there have a clue? Nicholas Paldino suggested something similar once, but had no example.
Tx!

//ecgn

Nov 15 '05 #2

P: n/a
Erik,

See http://www.msjogren.net/dotnet/eng/s..._shelllink.asp

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #3

P: n/a
Thanks Mattias and Nicholas!

That is absolutely brilliant; exactly what I was looking for. =o

//ecg

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.