How to access URL and bookmark title in .URL files?

夙愿已清 提交于 2019-12-04 16:59:59

I opened a .url in Notepad++ and this is what I found. Note, this was generated in IE8. This page has a detailed look into the format of the .url (internet shortcut) file.

[DEFAULT]
BASEURL=http://www.google.com.au/
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[InternetShortcut]
URL=http://www.google.com.au/
IDList=
IconFile=http://www.google.com.au/favicon.ico
IconIndex=1

You should be able to parse this easily using basic StreamReader IO.

The current format of a .url file is not set in stone and could change in any OS update. The right way to parse these files is via the CLSID_InternetShortcut COM coclass, using IUniformResourceLocator and IPropertyStorage. I just added that capability to TvGameLauncher, you can take the code from the InternetShortcut folder (Apache 2.0 License).

Sample usage:

var shortcut = new InternetShortcutManaged(@"MyShortcut.url");

Console.WriteLine("URL: " + shortcut.Url);
Console.WriteLine("Working dir: " + shortcut.WorkingDir);
Console.WriteLine("Icon file: " + shortcut.IconFile);
Console.WriteLine("Icon index: " + shortcut.IconIndex);
Console.WriteLine("Name: " + shortcut.Name);
Console.WriteLine("Description: " + shortcut.Description);
Console.WriteLine("Comment: " + shortcut.Comment);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!