728x90
반응형
728x170
▶ 바로가기 생성하기 예제
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);
728x90
▶ 바로가기 생성하기
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 항목을 참조한다.
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] IEnumerable<T> 객체에서 특정 속성을 키 값으로 딕셔너리 구하기 (0) | 2017.07.08 |
---|---|
[C#/COMMON] ReadOnlyCollection<T> 클래스 : 읽기 전용 컬렉션 구하기 (0) | 2017.07.03 |
[C#/COMMON] 공용체 사용하기 (0) | 2017.07.03 |
[C#/COMMON] ManagementClass 클래스 : MAC 주소 구하기 (0) | 2017.07.03 |
[C#/COMMON] 바로가기 생성하기 (0) | 2017.06.29 |
[C#/COMMON] Assembly 클래스 : GetExecutingAssembly 정적 메소드를 사용해 애플리케이션 실행 디렉토리 경로 구하기 (0) | 2017.06.22 |
[C#/COMMON] MD5CryptoServiceProvider 클래스 : MD5 해시값 구하기 (0) | 2017.06.22 |
[C#/COMMON] SHA512Managed 클래스 : SHA512 해시값 구하기 (0) | 2017.06.22 |
[C#/COMMON] SHA384Managed 클래스 : SHA384 해시값 구하기 (0) | 2017.06.22 |
[C#/COMMON] SHA256Managed 클래스 : SHA256 해시값 구하기 (0) | 2017.06.22 |
댓글을 달아 주세요