첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요