Copy shortcut from desktop

TyB

Well-known member
Joined
May 14, 2009
Messages
102
Programming Experience
3-5
What I'm trying to do is copy a shortcut from my desktop to my form. So the I would have a shortcut on my form just like the desktop.

Thoughts?

Thanks,

Tyler
 
Desktop shortcuts are files. You can't copy a file onto your form. What you could do is read the contents of the file and then use that to create something on your form that you can click, like a Button, LinkLabel or whatever. When the corresponding event is raised you can call Process.Start to execute the corresponding file or whatever.

I don't know what format the LNK file is in as I've never looked. It might be text, in which case you can open it in Notepad to discern the format. In that case you can use a StreamReader or the like to read the file. If it's in binary format then that will be more difficult, and you'll have to do some reading on what the data means. To read it you can then use a FileStream or BinaryReader.
 
Thanks J,

I can get the information for where the shortcut points and I can get the path of the icon however I am unable to get the icon to use as an image for a clickable control.

I tried to extract the icon from the path, but it always fails. The path is something like C:\Windows\Installer\{A38C1821-9638-4D4A-BE74-B1970F49D8FD}\_C97D7C988FF14AB96BAF53.exe,0

Ty
 
Back
Top