Create shortcut
Peponi │ 11/19/2024 │ 1m
C#
COMIWshRuntimeLibraryLink.lnk
Create shortcut
11/19/2024
1m
Peponi
C#
COMIWshRuntimeLibraryLink.lnk
1. Introduction
아래는 코드를 이용해 바로가기를 생성하는 방법이다. COM 라이브러리 중 Windows Script Host Object Model
을 추가한 후, IWshRuntimeLibrary
를 using
선언하여 사용한다.
2. Code
using System;
using System.IO;
using System.Windows.Forms;
using IWshRuntimeLibrary;
namespace CreateShortcut
{
public static class Shortcut
{
private static string _appStartMenuPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "MyProject");
public static void AddShortcut()
{
if (!Directory.Exists(_appStartMenuPath))
Directory.CreateDirectory(_appStartMenuPath);
string exeLocation = Path.Combine(_appStartMenuPath, "MyProject.exe" + ".lnk");
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(exeLocation);
shortcut.Description = "MyProject's description";
shortcut.IconLocation = Application.StartupPath + "projectIcon.ico";
shortcut.TargetPath = Application.ExecutablePath;
shortcut.WorkingDirectory = Application.StartupPath;
shortcut.Save();
}
}
}