添加引用:

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;
            }
        }

 

相关文章:

  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-10-19
  • 2022-02-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-28
  • 2021-07-13
  • 2021-11-23
  • 2021-08-18
  • 2022-02-26
  • 2021-08-16
相关资源
相似解决方案