C# “快捷方式” 实现程序开机启动

添加引用:

COM : Windows Script Host Object Model

Name: Interop.IWshRuntimeLibrary

添加命名空间:

using IWshRuntimeLibrary;

        public static int StartUpByShortCut(string targetPath, string name, string desc)
        {
            try
            {
                WshShell shell = new WshShell();

                WshShortcut st = shell.CreateShortcut(
                    Environment.GetFolderPath(Environment.SpecialFolder.Startup) +
                    System.IO.Path.DirectorySeparatorChar + name + ".lnk");

                st.Description = desc;
                st.IconLocation = targetPath + ",0";
                st.TargetPath = targetPath;
                st.WindowStyle = 1;
                st.WorkingDirectory = System.IO.Directory.GetParent(targetPath).FullName;
                st.Save();
                return 1;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return 0;
            }
        }
原文地址:https://www.cnblogs.com/wjshan0808/p/4808971.html