我做了一个winform程序,如何让程序在系统启动的时候就启动?

解决方案 »

  1.   


      //获取程序执行路径..
      string starupPath = Application.ExecutablePath;
      
      RegistryKey loca = Registry.LocalMachine;
      RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");  try
      {
      //SetValue:存储值的名称
      run.SetValue("360", starupPath);
       loca.Close();
      }
      catch 
      {
       
      }
      

  2.   

    把程序拖入开始菜单的启动项。。或者写入注册表。。
    这里有代码
       //开机启动
            private void StartUp(bool b)
            {
                /* 20100527
                //string StartupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
                //System.IO.File.Copy("应用程序路径(包括程序名)", StartupPath + "执行程序文件名称", true);            //获得文件的当前路径  
                string dir = Directory.GetCurrentDirectory();
                //获取可执行文件的全部路径  
                string exeDir = dir + @"\xxxx(程序名称).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键中写入一个新的键值  
                if (b)
                    key6.SetValue("myForms", exeDir);
                else
                    //取消
                    key6.SetValue("myForms", false);
                key6.Close();
                */
            }
      

  3.   

    你是否希望实现,瑞星杀毒那样的情况,就是在用户登录界面上,就能看到并使用瑞星的图标了?
    如果这样,你可以试试看下面的方法:
    1、在某个用户登录时,启动程序,修改注册表
    HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run  2、在所有用户登录时,都启动程序,修改注册表
    HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run.微软给出的示例代码:
    http://www.geekpedia.com/sample/RunAtStartup/RunAtStartup.zip