温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

C#应用添加桌面快捷方式和开机启动

发布时间:2020-08-09 15:22:42 来源:网络 阅读:717 作者:wzwyc 栏目:编程语言
        #region 快捷方式
        private static void CreateDesktopLnk()
        {
            string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
            if (DesktopPath.ToLower().Equals(Application.StartupPath.ToLower()) == false)
                CreateDesktopLnkEx(DesktopPath, ShortCutFileName);

            //string StartupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            //CreateDesktopLnkEx(StartupPath, ShortCutFileName);
        }

        private static void CreateDesktopLnkEx(string LnkPath, string LnkFileName)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(LnkPath + "\\" + LnkFileName);
            shortcut.TargetPath = Application.ExecutablePath;
            shortcut.Arguments = "";
            shortcut.Description = AppName;
            shortcut.WorkingDirectory = Application.StartupPath;
            shortcut.IconLocation = Application.ExecutablePath + ",0";
            shortcut.WindowStyle = 1;
            shortcut.Save();
        }
        #endregion

之前想着如何让应用开机启动的时候,有想着去添加注册表之类的,非常的麻烦,WIN7以上的系统还涉及到管理员权限的问题。其实最方便的实现方法就是直接在系统的“启动”目录下建立一个快捷方式。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI