■ 바로가기를 생성하는 방법을 보여준다.
▶ 바로가기 생성하기 예제 (C#)
1 2 3 4 5 6 7 8 9 10 11 |
using System; using System.IO; string filePath = "c:\\Voyager.exe"; string desktopDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string shortcutFilePath = Path.Combine(desktopDirectoryPath, "Voyager.lnk"); string iconFilePath = "c:\\Voyager.ico"; CreateShortcut(filePath, desktopDirectoryPath, iconFilePath); |
▶ 바로가기 생성하기 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
using System.IO; using IWshRuntimeLibrary; #region 바로가기 생성하기 - CreateShortcut(filePath, shortcutDirectoryPath, shortcutIconFilePath, shortcutDescription) /// <summary> /// 바로가기 생성하기 /// </summary> /// <param name="filePath">파일 경로</param> /// <param name="shortcutDirectoryPath">바로가기 디렉토리 경로</param> /// <param name="shortcutIconFilePath">바로가기 아이콘 파일 경로</param> /// <param name="shortcutDescription">바로가기 설명</param> public void CreateShortcut ( string filePath, string shortcutDirectoryPath, string shortcutIconFilePath = null, string shortcutDescription = null ) { if(string.IsNullOrWhiteSpace(filePath) || !System.IO.File.Exists(filePath)) { return; } if(string.IsNullOrWhiteSpace(shortcutDirectoryPath) || !Directory.Exists(shortcutDirectoryPath)) { return; } string shortcutFileName = string.Format(Path.GetFileNameWithoutExtension(filePath) + ".lnk"); string shortcutFilePath = Path.Combine(shortcutDirectoryPath, shortcutFileName); WshShell shell = new WshShell(); IWshShortcut shortcut = shell.CreateShortcut(shortcutFilePath) as IWshShortcut; shortcut.TargetPath = filePath; shortcut.WorkingDirectory = Path.GetDirectoryName(filePath); if ( !string.IsNullOrWhiteSpace(shortcutIconFilePath) && System.IO.File.Exists(shortcutIconFilePath) && shortcutIconFilePath.EndsWith(".ico") ) { shortcut.IconLocation = shortcutIconFilePath; } if(!string.IsNullOrWhiteSpace(shortcutDescription)) { shortcut.Description = shortcutDescription; } shortcut.Save(); } #endregion |
※ "Windows Script Host Object Model" COM 항목을 참조한다.