473,586 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2600
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 GetTypeFromCLSI D 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 UCOMIPersistFil e 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.co m
"Erik Cedergren (ecgn)" <an*******@disc ussions.microso ft.com> wrote in
message news:51******** *************** ***********@mic rosoft.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
17153
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 allow the users to add a shortcut (with icon) on their desktop, as well as seeing the icon in the URL. Our development server allows both HTTP and...
5
2566
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
2869
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 displayed at the left of the name of the page. How do I do this? I am using Frontpage 2002, but know how to edit HTML manually. Thanks,
4
2097
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: http://espn.go.com/
17
1997
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 notice their examples show <link rel="stylesheet" type="text/css" href="style101.css"> with the stylesheet quoted, as other attributes are. It...
0
961
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 have VB 2005 Express. The conversion failed. If anyone is interested, here it is: Function StoredLinkPath(LnkPicPath as string) as string Dim shl...
0
1024
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 clicking on them won't work, even if I am setting the navigateUrl attribute to "#another_form" . Its just reloading the current form. Here's a...
1
3403
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): /usr/local/file.c ln -s /usr/local/file.c fileX1.c (absolute path) ln -s file.c fileX2.c (relative path) Assume samba has been set...
0
7841
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7965
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1184
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.