NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 10 11 12 13 14 … 93 Next »
Windows Shortcuts

 
  • 0 Vote(s) - 0 Average
Windows Shortcuts
ACTCMS
Offline

Posting Freak

UK
Posts: 2,730
Threads: 101
Joined: Jun 2007
#1
2012-03-23, 10:24 PM
Is there a way to get the target of a Windows Shortcut (.lnk) without having to reference Shell32?

If not, would having the Interop.Shell32.dll in my plugin folder cause any problems?
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#2
2012-03-23, 11:35 PM
There are a few sites out there which have the .LNK format details as a result of reverse-engineering but it looks fairly complex to parse.

I can't think of any reason why using Interop.Shell32.dll would be a problem.

Not sure if you've already been playing with it but I found this along the way...
Code:
public string GetShortcutTargetFile(string shortcutFilename)
{
    string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename);
    string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);

    Shell32.Shell shell = new Shell32.ShellClass();
    Shell32.Folder folder = shell.NameSpace(pathOnly);
    Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
    if (folderItem != null)
    {
        Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
        return link.Path;
    }
    return ""; // not found
}

Cheers,
Brian
ACTCMS
Offline

Posting Freak

UK
Posts: 2,730
Threads: 101
Joined: Jun 2007
#3
2012-03-23, 11:44 PM
bgowland Wrote:Not sure if you've already been playing with it but I found this along the way...
Code:
public string GetShortcutTargetFile(string shortcutFilename)
{
    string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename);
    string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);

    Shell32.Shell shell = new Shell32.ShellClass();
    Shell32.Folder folder = shell.NameSpace(pathOnly);
    Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
    if (folderItem != null)
    {
        Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
        return link.Path;
    }
    return ""; // not found
}
Thanks Brian - I found that too and that's exactly what I'm currently using - I was just wondering if there was another way...

Alex
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#4
2012-03-24, 12:06 AM
ACTCMS Wrote:Thanks Brian - I found that too and that's exactly what I'm currently using - I was just wondering if there was another way...
You could probably do it with [DllImport("shell32")] and by defining the individual methods you need using
Code:
private static extern <return-type> <method-name>(<params>);
but I suspect the Interop.Shell32.dll is probably just a wrapper class which does this for you.

Cheers,
Brian
mvallevand
Offline

Posting Freak

Ontario Canada
Posts: 52,766
Threads: 954
Joined: May 2006
#5
2012-03-24, 12:22 AM
Here's a BinaryReader version http://thelightness.blogspot.ca/2005/07/...-in-c.html only because you said you were looking for alternatives.

Martin
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  Windows FM Radio support in v5. mvallevand 125 25,859 2023-01-29, 08:13 PM
Last Post: mvallevand
  Problems with Windows UWP App spitefulgod 4 3,762 2016-12-15, 08:35 PM
Last Post: spitefulgod
  Any ideas about programming for Windows Firewall? bgowland 4 5,543 2014-04-10, 09:05 AM
Last Post: bgowland
  Creating a Windows service McBainUK 8 3,331 2011-03-30, 03:29 AM
Last Post: mvallevand
  Using Windows file system shortcuts ACTCMS 0 1,776 2010-01-26, 11:45 PM
Last Post: ACTCMS
  Windows Media Connect - Storing stuff on a Home Server psycik 3 2,636 2009-09-29, 03:47 AM
Last Post: mvallevand
  Launch windows screensaver McBainUK 4 2,292 2008-07-31, 11:03 AM
Last Post: Reddwarf
  SLightly OT - Windows Services jtokach 4 2,070 2007-04-24, 08:58 PM
Last Post: jtokach
  System.Windows.Forms.KeyEventArgs e tostring reven 1 2,531 2005-01-04, 02:45 PM
Last Post: KingArgyle

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode