473,379 Members | 1,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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

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
3 2582
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
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
Thanks Mattias and Nicholas!

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

//ecg

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Todd Peterson | last post by:
I'm encountering some wierd behavior with a <link> tag over an HTTPS connection, vs. an HTTP connection... In an ASP/HTML page on my website, I've add a <link rel="shortcut icon"...> in order to...
5
by: Supra | last post by:
how do i get icon from url into combobox? i already got webbrowser working it is lsimilar if u typed www.firefox.com, u will c icon stored in combobox. ne ideas how to do this? regards, supra
8
by: Ed Isenberg | last post by:
I notice that a lot of Web pages have an icon that is displayed preceding the URL in the place in the browser where the URL is displayed. When I bookmark or add this to Favorites the icon is also...
4
by: Ray Stevens | last post by:
Is it possible to place a company icon (logo) in the browser address field so that if a user copies it as a shortcut to his desktop the icon will be there. For example, like this:...
17
by: Eric Lindsay | last post by:
For years I have had links to a stylesheet done like <link rel=stylesheet type="text/css" href="style.css"> and these pages all validate with the W3C validator. However in looking at W3C, I...
0
by: anger2headshot | last post by:
Hi, does anyone know how to get the location stored in a .lnk file? I have tried to open one in Notepad and a garbled mess came up. I've found some code but it was for VB6 which I do not have, I only...
0
by: =?iso-8859-1?B?QW3p?= | last post by:
Hi! I am new to asp.net and mobileControls. I am reading adresses from a Database and would like to create links that would lead to another page. At this point, I am able to create the links but...
1
by: andredz | last post by:
Is there away to access some NFS symlink files that are set using absolute paths from Windows? I'm able to access symlink files is there are set using relative paths. Assume on Linux (mylinux):...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.