private static string GetShortcutTargetFile(string shortcutFilePath) { IWshShell shell = null; // シェルオブジェクト IWshShortcut shortcut = null; // ショートカットオブジェクト try { //--------------------------------------------------------------------------------- // オブジェクト作成 //--------------------------------------------------------------------------------- // シェルオブジェクト作成 shell = new WshShell(); // ショートカットオブジェクト作成 //--------------------------------------------------------------------------------- // ショートカット プロパティ設定 //--------------------------------------------------------------------------------- shortcut = (IWshShortcut)shell.CreateShortcut(shortcutFilePath); // ショートカットのリンク先を設定 return(shortcut.TargetPath); } finally { //--------------------------------------------------------------------------------- // COMオブジェクト解放 //--------------------------------------------------------------------------------- // ショートカットオブジェクトの解放 if (shortcut != null) { Marshal.ReleaseComObject(shortcut); } // シェルオブジェクトの解放 if (shell != null) { Marshal.ReleaseComObject(shell); } } }
static public void CreateShortcut(string shortcutPath, string targetPath) { WshShell shell = null; IWshShell shellInterface = null; IWshShortcut shortcut = null; try { shell = new WshShell(); shellInterface = (IWshShell)shell; shortcut = shellInterface.CreateShortcut(shortcutPath); shortcut.Description = targetPath; shortcut.TargetPath = targetPath; shortcut.IconLocation = targetPath + ",0"; shortcut.Save(); } finally { Release(shortcut); Release(shellInterface); Release(shell); } }