
| using System using System.IO; ////////////////////////////// string linkFilePath = "ショートカットファイルのパス"; string targetPath; //得られたパスを格納する変数. Shell32.ShellClass shellClass = new Shell32.ShellClass(); Shell32.Folder folder = shellClass.NameSpace(GetDirectoryName(linkFileName)); Shell32.FolderItem folderItem = folder.ParseName(GetFileName(linkFileName)); if (folderItem.IsLink) { Shell32.ShellLinkObject linkObject = folderItem.GetLink as Shell32.ShellLinkObject; targetFileName = linkObject.Path; //得られたパス } |
| using System; using System.Runtime.InteropServices; using System.Windows.Forms; ////////////////////////////// class Win32 { public const int MAX_PATH = 256; [DllImport("shell32.dll", EntryPoint = "#62")] public static extern int SHChangeFolderDialog(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszFileName, int filePathLength, ref int iconIndex); } ////////////////////////////// //あとはこんな感じで利用 int iconIndex = 0; StringBuilder lpszFileName = new StringBuilder("ファイルのパス", Win32.MAX_PATH); if (Win32.SHChangeFolderDialog(IntPtr.Zero, lpszFileName, Win32.MAX_PATH, ref iconIndex) == DialogResult.OK) { //lpszFileName と iconIndex を利用. } |