Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.IO;
- internal static class ShortcutHelper
- {
- internal static bool IsShortcut(string path)
- {
- if (!File.Exists(path))
- {
- return false;
- }
- string directory = Path.GetDirectoryName(path);
- string file = Path.GetFileName(path);
- Shell32.Shell shell = new Shell32.Shell();
- Shell32.Folder folder = shell.NameSpace(directory);
- Shell32.FolderItem folderItem = folder.ParseName(file);
- if (folderItem != null)
- {
- return folderItem.IsLink;
- }
- return false;
- }
- internal static string ResolveShortcut(string path)
- {
- if (IsShortcut(path))
- {
- string directory = Path.GetDirectoryName(path);
- string file = Path.GetFileName(path);
- Shell32.Shell shell = new Shell32.Shell();
- Shell32.Folder folder = shell.NameSpace(directory);
- Shell32.FolderItem folderItem = folder.ParseName(file);
- Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
- return link.Path;
- }
- return string.Empty;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment