如果实现起来不是很复杂 一般不建议修改注册表如果要弹出的是一个messagebox的话可以这么做判断线程是否运行(例如explorer)如果运行 弹出来就可以了。

解决方案 »

  1.   

    或者到注册表的HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run中新建一个启动项
      

  2.   

    static void Main(string[] args)
            {
                System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();            timer1.Tick += new EventHandler(timer1_Tick);
                timer1.Interval = 60000;
                if (timer1.Enabled == false)
                        timer1.Enabled = true;
                try
                {
                    //获得文件的当前路径  
                    string dir = Directory.GetCurrentDirectory();
                    //获取可执行文件的全部路径  
                    string exeDir = dir + "\\ConsoleApp.exe";                //获取Run键  
                    RegistryKey key1 = Registry.LocalMachine;
                    RegistryKey key2 = key1.CreateSubKey("SOFTWARE");
                    RegistryKey key3 = key2.CreateSubKey("Microsoft");
                    RegistryKey key4 = key3.CreateSubKey("Windows");
                    RegistryKey key5 = key4.CreateSubKey("CurrentVersion");
                    RegistryKey key6 = key5.CreateSubKey("Run");
                    //在Run键中写入一个新的键值  
                    key6.SetValue("consoleApp", exeDir);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("运行失败,请重新尝试", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
      

  3.   

    或者写个windows服务好了
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.ServiceProcess;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using Microsoft.Win32;
    using System.Threading;namespace WinSer
    {
        
        public partial class Service1 : ServiceBase
        {
            System.Threading.Timer timer1=null;
            
            public Service1()
            {
                InitializeComponent();           
            }        protected override void OnStart(string[] args)
            {
                // TODO: 在此处添加代码以启动服务。  
                timer1 = new System.Threading.Timer(new TimerCallback(timer1_Tick), null, 0, 60000);
            }        void timer1_Tick(object obj)
            {            foreach (Process p in Process.GetProcesses())
                {
                    if (p.ProcessName == "Client")
                    {
                        p.Kill();
                        return;
                    }
                }
            }        protected override void OnStop()
            {
                // TODO: 在此处添加代码以执行停止服务所需的关闭操作。        
            }
        }
    }
      

  4.   

            private void button1_Click(object sender, EventArgs e)
            {
                string strName = Application.ExecutablePath;
                if (!File.Exists(strName))
                    return;
                string strnewName = strName.Substring(strName.LastIndexOf("\\") + 1);
                RegistryKey RKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                if (RKey == null)
                    RKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                RKey.SetValue(strnewName, strName);
                MessageBox.Show("程序设置完成,重新启动计算机后即可生效!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
      

  5.   

    我觉得奇怪,RKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); 
    本来不是已经有这个目录了吗?为什么还要Create?
      

  6.   

    你可以用windows服务。具体怎么写,你应该可以找到。
      

  7.   


            private void FrmTiming_Load(object sender, EventArgs e)
            {
                AutoRun();             
            }
           /// <summary>
           /// windows启动时,自动运行
            /// </summary>
            private void AutoRun()
            {
                try
                {
                    string path = Application.ExecutablePath;
                    if (!System.IO.File.Exists(path))
                        return;
                    string myName = path.Substring(path.LastIndexOf("\\") + 1);
                    RegistryKey myReg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                    if (myReg == null)
                        myReg = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                    myReg.SetValue(myName, path);
                }
                catch
                {
                    Application.Exit();
                }        }
      

  8.   

    using Microsoft.Win32;//Registry的引用空间.
      

  9.   

    如果做过应用的话你会发现上面所有的方法都会启动时很慢所以现在做桌面应用我全部都用vc6windows服务我还没有试过