• 0

[C#] resolve .lnk files


Question

So I've found this tutorial:

http://www.geektieguy.com/2007/11/19/how-t...rtcuts-using-c/

But in reading it, when I try to parse files through it, null is returned. Some users say they have this problem as well, but using the "I use the WshShell way instead." Seems to work.

Although this article doesn't explicitly say how to use it (or I'm not understanding it correctly). Anyone have any idea what they're talking about/how to do it.

Link to comment
https://www.neowin.net/forum/topic/658928-c-resolve-lnk-files/
Share on other sites

5 answers to this question

Recommended Posts

  • 0
Examine it... I need to resolve the file that it is pointing to.. (I'm not going to run it).

Add a COM reference to Windows Script Host Object Model.

using System;
using System.IO;
using IWshRuntimeLibrary;

namespace csCon
{
	class Program
	{
		static void Main ( string[] args )
		{
			string dir = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
			var di = new DirectoryInfo(dir);
			FileInfo[] fis = di.GetFiles();
			if (fis.Length > 0) {
				foreach(FileInfo fi in fis) {
					if (fi.FullName.EndsWith("lnk")) {
						IWshShell shell = new WshShell();
						var lnk = shell.CreateShortcut(fi.FullName) as IWshShortcut;
						if(lnk != null) {
							Console.WriteLine("Link name: {0}", lnk.FullName);
							Console.WriteLine("link target: {0}", lnk.TargetPath);
							Console.WriteLine("link working: {0}", lnk.WorkingDirectory);
							Console.WriteLine("description: {0}", lnk.Description);
						}
						break;
					}					
				}
			}
		}
	}
}

Edited by azcodemonkey
  • 0

I search how to open file in a TreeView. I simply need to open some PDF and Url, this part work perfectly, but...

I also need to open PDF from lnk file.

This is on a website, in asp.net with C#.

I try this way :

IWshShell shell = new WshShell();
					IWshShortcut lnk = shell.CreateShortcut(MapPath(path) + "/" + text) as IWshShortcut;
aNode.NavigateUrl = lnk.TargetPath

...and the file doesn't not open when I click on the node.

BUT when I run the debug on my localhost, When I right click and save as the file, this work. I don't understand...

On the server, when I deploy the website, the target of the lnk node doesn't not change... That's weird...

Any idea for helping ?

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Autonomous post-training loop placed 8th of 4,000 and then rewrote its own evaluation strategy. An autonomous AI system built by researchers at Amazon's A-EVO-Lab completed a full post-training run on a 30 billion parameter NVIDIA Nemotron model — with no human in the loop, across four rounds running over multiple weeks — and then did something its designers had not planned for: it detected that its own internal evaluation metric had become misleading and redesigned the search strategy it was using to improve itself. https://www.techtimes.com/articles/319123/20260626/nvidia-ai-trained-itself-30b-model-corrected-its-own-broken-metric-mid-run.htm
    • Grok Adult Content Tops 10 Billion Images Monthly More than half of all traffic flowing through Grok, Elon Musk's flagship AI product, now comes from users requesting pornographic images, explicit videos, and **** roleplay https://www.techtimes.com/articles/319142/20260626/grok-adult-content-tops-10-billion-images-monthly-xai-engineers-admit-csam-has-no-fix.htm
    • If Ford would stop hiring SUITS to run the company, and put CAR GUYS back in charge perhaps they could do better. Heck, the only CAR they produce today is the Mustang. Hey Ford! Not everyone needs/wants an overpriced SUV or pickup truck that is so tall you have to have a step ladder to get in and out of it.
    • Amazing how some will just jump all over something. Probably the same people that thought Musk was a "tech god" before he saddled up with "bad orange man". Before, they worshiped at his feet, including a lot of so called hollywood types. Now, because he fell off the plantation truck, they toss him under the bus.
  • Recent Achievements

    • One Year In
      bernmeister earned a badge
      One Year In
    • Week One Done
      Scoobystu earned a badge
      Week One Done
    • Week One Done
      tuben earned a badge
      Week One Done
    • First Post
      OffsetAbs earned a badge
      First Post
    • Reacting Well
      OffsetAbs earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      492
    2. 2
      +Edouard
      225
    3. 3
      PsYcHoKiLLa
      161
    4. 4
      Steven P.
      75
    5. 5
      FloatingFatMan
      71
  • Tell a friend

    Love Neowin? Tell a friend!