ITPub博客

首页 > Linux操作系统 > Linux操作系统 > WINFORM开机自动运行

WINFORM开机自动运行

原创 Linux操作系统 作者:fangqm 时间:2010-06-06 23:05:04 0 删除 编辑
 ///
        /// 设置指定完整路径下应用程序是否开机运行
        ///

        /// 应用程序完整路径
        /// 是否开机运行
        void SetBootAutoRun(string exePath, bool isruned)
        {
            //应用程序完整路径Application.ExecutablePath;
            //获取应用程序文件名
            string filename = exePath.Substring(exePath.LastIndexOf("\\") + 1);
            if (isruned)
            {//开机运行程序
                if (!File.Exists(exePath))//指定文件是否存在 
                    return;
                Microsoft.Win32.RegistryKey Rkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                if (Rkey == null)
                    Rkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                Rkey.SetValue(filename, exePath);//修改注册表,使程序开机时自动执行。 
            }
            else
            {//关闭开机运行
                //修改注册表,使程序开机时不自动执行。 
                Microsoft.Win32.RegistryKey Rkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                Rkey.DeleteValue(filename, false);
            }
        }

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23109131/viewspace-664522/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
创业项目 https://u.rscode.cn

注册时间:2010-03-24

  • 博文量
    297
  • 访问量
    784625