• 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
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
Link to comment
Share on other sites

  • 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 ?

Link to comment
Share on other sites

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

    • No registered users viewing this page.