C#为应用程序创建快捷方式

作者:陆金龙    发表时间:2015-05-24 11:53   


通常安装玩客户端,需要为应用程序创建桌面快捷方式。C#创建的快捷方式的代码如下:

private void Createshort(string name, string description, string targetPath)
{
    if (!name.EndsWith(".lnk"))
    {
        name += ".lnk";
    }
    WshShell shell = new WshShell(); 
    IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
        Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "//" + name);
    shortcut.TargetPath = targetPath; //快捷方式的目标所在的位置
    shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);//应用程序的工作目录 
    shortcut.WindowStyle = 1;        //1.Normal,3.Maximized,7.Minimized
    shortcut.Description = description;
    shortcut.Save(); 
}