3

I want to get title of shortcut, not file name, not description, but title. how to get it?

I have learn to resolve its target path from here, How to resolve a .lnk in c#

but i don't find any method to get its title.


(source: ggpht.com)


(source: ggpht.com)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Cooper.Wu
  • 4,335
  • 8
  • 34
  • 42
  • What do you mean by title? There's no title entry in the properties for a shortcut, nor in the IShellLink docs. – paxdiablo Apr 29 '09 at 04:20
  • I know it, but on Vista, the Notepad.lnk display "记事本"(Chinese Notepad Means). but the filename is the Notepad.lnk. – Cooper.Wu Apr 29 '09 at 09:42
  • This website can't post image, so i can't upload the picture do show my question... – Cooper.Wu Apr 29 '09 at 09:43

6 Answers6

2

It sounds like you might be trying to get the title of the file the link points to, as JRL suggests.

If you're not trying to do that, I'd recommend opening up one of these .lnk files in a hex editor like XVI32. You can probably tell from there whether the Chinese name displayed is embedded in the .lnk file or is somewhere else.

If it's somewhere else, it may be an Extended File Property. There's some source code that may help with retrieving that info: Extended File Properties

If by some chance it is inside the .lnk file, I recommend looking at the Windows Shortcut Specification to get offset information and such on the location of that data.

Steven Richards
  • 2,802
  • 19
  • 18
1

You can use the property system APIs in latest relase of Code pack:

(all the 670+ properties in the system are accesible using simple property accessors)

http://code.msdn.microsoft.com/WindowsAPICodePack

I know your current need is only limited title of lnk files. Using the above library, the sample code might look like:

ShellLink myLink = ShellObject.FromParsingName("c:\somepath\myLink.lnk");

string title = myLink.Properties.System.Title.Value;

// This is what its pointing to... string target = myLink.Properties.System.TargetParsingPath.Value;

Keeron
  • 101
  • 2
1

There is a Desktop.ini hidden file in shortcuts directory, the Desktop.ini file records display strings info of shortcuts.

Desktop.ini file sample:

 [LocalizedFileNames]
Windows Update.lnk=@%SystemRoot%\system32\wucltux.dll,-1
Default Programs.lnk=@%SystemRoot%\system32\sud.dll,-1
Cooper.Wu
  • 4,335
  • 8
  • 34
  • 42
0

Please define "title". The only attributes that sound relevent are the shortcut's file name, the target's file name, and the .lnk file's description data.

Anonymous
  • 49,213
  • 1
  • 25
  • 19
  • 2
    @Anon, answers aren't generally to be used as a discussion board. This is better left as a comment to the question - you risk downvotes by doing this (not from me since I'm lenient with newcomers). – paxdiablo Apr 29 '09 at 04:28
  • I asked for clarification. If this was more appropriate for a comment, then you're saying I'm not allowed to ask for clarification? Comments require 50 "reputation", and "answers" do not. Please explain exactly what I should be doing differently. – Anonymous Apr 29 '09 at 04:31
  • This clarification has already been requested in the comments. – paxdiablo Apr 29 '09 at 04:33
  • It wasn't there when I posted this. My question stands. – Anonymous Apr 29 '09 at 04:34
  • Really? It says 16mins ago, your "answer" was 11mins ago. I hope it didn't take 5 minutes to type that in. – paxdiablo Apr 29 '09 at 04:37
  • Between researching the question and typing in this text box that slows down every keypress, yes it took over five minutes to _respond_ to the question. – Anonymous Apr 29 '09 at 05:10
  • Yes, you cannot ask for clarification in answers. If you don't have enough repuration to post a comment, you cannot ask for clarification at all. The world isn't fair :) – Sander Apr 29 '09 at 05:22
  • The world is poorly-documented and uses Javascript when it doesn't have to. That doesn't mean every site should follow the example. – Anonymous Apr 29 '09 at 05:49
0

Assuming you mean the title of the file the link points to, not the link itself, and that you are talking about Windows, then it's done via a feature in NTFS, alternative streams. You can access those streams using code in this article.

JRL
  • 76,767
  • 18
  • 98
  • 146
-1

Looking around on creating shortcuts, looks like there's a lot of jumping through hoops with scripting objects. But am I missing something? If you have a path to the shortcut, the name should be exactly what you find in the path, not some attribute you have to look up.

    Dim f As FileInfo = New FileInfo("C:\Name of shortcut.lnk")
    Dim title As String = f.Name.Replace(".lnk", String.Empty)
Joshua Belden
  • 10,273
  • 8
  • 40
  • 56
  • NO, I don't need the filename. Thanks for your reply. to get the filename without i will use 'Path.GetFileNameWithoutExtension' – Cooper.Wu Apr 29 '09 at 04:10