看得破的人,处处都是生机;

看不破的人,处处都是困境;

拿得起的人,处处都是担当;

拿不起的人,处处都是疏忽;

放得下的人,处处都是大道;

放不下的人,处处都是迷茫;

想得开的人,处处都是春天;

想不开的人,处处都是凋枯;

做何人,在自己;

小自我,大天地;

c# 开机启动项

  //路径, 添加开机启动/删除开机启动

        public static void SetAutoRun(string fileName, bool isAutoRun)
        {
            RegistryKey reg = null;
            try
            {
                if (!System.IO.File.Exists(fileName))
                    throw new Exception("该文件不存在!");
                String name = fileName.Substring(fileName.LastIndexOf(@"\") + 1);
                reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
                if (reg == null)
                    reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
                if (isAutoRun)
                    reg.SetValue(name, fileName);
                else
                    reg.SetValue(name, false);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                if (reg != null)
                    reg.Close();
            }

        }

posted @ 2013-03-20 14:14  心电心  阅读(250)  评论(0编辑  收藏  举报