Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Read location in .lnk (shortcut) file

Read location in .lnk (shortcut) file

Scheduled Pinned Locked Moved C#
adobequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StyrofoamSUV
    wrote on last edited by
    #1

    Is there any way to read the file that a .lnk (shortcut) refers to? Opening the file in Notepad shows that it is not plain text (such as Adobe Gamma Loader.lnk which loads Program Files\Common Files\Adobe\Calibration\Adobe Gamma Loader.exe). I am wondering if there is any way to read a .lnk file's location using some sort of library. Thanks, Josh

    K 1 Reply Last reply
    0
    • S StyrofoamSUV

      Is there any way to read the file that a .lnk (shortcut) refers to? Opening the file in Notepad shows that it is not plain text (such as Adobe Gamma Loader.lnk which loads Program Files\Common Files\Adobe\Calibration\Adobe Gamma Loader.exe). I am wondering if there is any way to read a .lnk file's location using some sort of library. Thanks, Josh

      K Offline
      K Offline
      kasik
      wrote on last edited by
      #2

      You can use the Windows Script Host Object Model COM library for this. If you're using Visual Studio, add a reference to it by selecting the COM tab from the Add Reference dialog and select "Windows Script Host Object Model". This will create an interop assembly called Interop.IWshRuntimeLibrary and will reference that. Then you can use the following code to extract the target file from a .lnk file...

      using IWshRuntimeLibrary;
       
      ...
       
      WshShell shell = new WshShell();
      IWshShortcut link = (IWshShortcut)shell.CreateShortcut( linkPath ); //where linkPath is the filepath to the .lnk file
       
      Process.Start( link.TargetPath ); //link.TargetPath points to the file the link targets

      Hope that helps :)


      “Accept that some days you are the pigeon, and some days you are the statue” -- David Brent Cheers, Will

      S 1 Reply Last reply
      0
      • K kasik

        You can use the Windows Script Host Object Model COM library for this. If you're using Visual Studio, add a reference to it by selecting the COM tab from the Add Reference dialog and select "Windows Script Host Object Model". This will create an interop assembly called Interop.IWshRuntimeLibrary and will reference that. Then you can use the following code to extract the target file from a .lnk file...

        using IWshRuntimeLibrary;
         
        ...
         
        WshShell shell = new WshShell();
        IWshShortcut link = (IWshShortcut)shell.CreateShortcut( linkPath ); //where linkPath is the filepath to the .lnk file
         
        Process.Start( link.TargetPath ); //link.TargetPath points to the file the link targets

        Hope that helps :)


        “Accept that some days you are the pigeon, and some days you are the statue” -- David Brent Cheers, Will

        S Offline
        S Offline
        StyrofoamSUV
        wrote on last edited by
        #3

        Thanks for the help Will. It works great. -Josh

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups