建立快捷键方式的方法

/// <summary>
        /// 建立快捷键方式的方法
        /// </summary>
        /// <param name="lnkName">快捷键方式的名称</param>
        /// <param name="appPath">目标程序的绝对路径</param>
        /// <param name="winStyleID">窗体风格标志 0:普通,3:最大,7:最小</param>
        /// <param name="description">快捷键方式的描述</param>
        /// <param name="iconPath">快捷键图标的绝对路径</param>
        /// <param name="hotKey">快捷键</param>
        public static void CreShortCut(string lnkName, string appPath, int winStyleID, string description,string iconPath,string hotKey)
        {
            if(!lnkName.ToLower().Contains(".lnk"))
            {
                lnkName = lnkName + ".lnk";
            }
            WshShell shell = new WshShell();         
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
                Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) +
                  "\\" + lnkName
                );
                shortcut.TargetPath = appPath;
                shortcut.WorkingDirectory = appPath.Substring(0,appPath.LastIndexOf("\\"));
                shortcut.WindowStyle = winStyleID;
                shortcut.Description = description;
                shortcut.IconLocation = iconPath;
                shortcut.Hotkey = hotKey;
                shortcut.Save();           
        }shell

相关文章
相关标签/搜索