如题,

解决方案 »

  1.   

    开机自动运行的话,可以在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run下面建一个string型value,值为你的可执行文件的路径至于“安装完成后自动启动”,我还真不知道这还能通过修改注册表来完成……
    你就让你的安装程序自己来启动不就成了么?
      

  2.   

    程序开机自动运行 string StartupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);       
               System.IO.File.Copy("应用程序路径(包括程序名)", StartupPath + "执行程序文件名称", true);        
          
                //获得文件的当前路径         
                string dir = Directory.GetCurrentDirectory();       
                //获取可执行文件的全部路径         
                string exeDir = dir + "WindowsApplication1.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("myForm",exeDir);         
              key6.Close();       
              
              //如果要取消的话就将key6.SetValue("myForm",exeDir);改成         
              //key6.SetValue("myForm",false);  
      

  3.   

    开机自动运行的话,可以在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run下面建一个string型value,值为你的可执行文件的路径
    这个方便
      

  4.   

    vainnetwork的对,也可以在runonce键值下,这样开机后只运行一次,以后开机就不运行了。
    如果放在run下的话,你可以设置安装完成后删除键值。
      

  5.   

    安装完自动运行:
      protected override void OnAfterInstall(System.Collections.IDictionary savedState)
            {
                base.OnAfterInstall(savedState);
                path = this.Context.Parameters["targetdir"] + "你的程序.exe";
                System.Diagnostics.Process.Start(path);  
             }
    写入注册表自启动:
    private void WriteReg()
            {
                RegistryKey KeyCon = Registry.LocalMachine.OpenSubKey(
                                            "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
                                            true);
                string MyKey = "你的程序";
                if ((string)KeyCon.GetValue(MyKey, "no") == "no")//指定的键不存在
                {
                    string Path = AppDomain.CurrentDomain.BaseDirectory + "你的程序.exe";
                    KeyCon.SetValue(MyKey, Path); //设置注册表中的启动键               
                }
            }
      

  6.   

    class WingRegeditWork : IWingRegeditWork
        {
            public WingRegeditWork()
            {
                
            }
            /// <summary>
            /// 写入注册表
            /// </summary>
            public void WriteToRegedit()
            {
                try
                {
                    string MyString = Application.ExecutablePath;
                    Microsoft.Win32.RegistryKey rootkey = Microsoft.Win32.Registry.LocalMachine;
                    Microsoft.Win32.RegistryKey Local = rootkey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
                    Local.SetValue("wing", MyString);
                }
                catch { }
            }
            /// <summary>
            /// 查询注册表里的值是否存在,是返回假,否返回真
            /// </summary>
            /// <returns></returns>
            public bool SelectMySelfInRegedit()
            {
                try
                {
                    string MyPath = Application.ExecutablePath;
                    Microsoft.Win32.RegistryKey rootKey = Microsoft.Win32.Registry.LocalMachine;
                    Microsoft.Win32.RegistryKey LocalValue = rootKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
                    string[] theValue = LocalValue.GetValueNames();
                    foreach (string str in theValue)
                    {
                        if (LocalValue.GetValue(str).ToString() == MyPath)
                        {
                            return false;
                        }
                    }
                    return true;
                }
                catch
                {
                    return true;
                }
            }        /// <summary>
            /// 删除注册表,成功返回假,不成功返回真
            /// </summary>
            public void DeleteToRegedit()
            {
                Microsoft.Win32.RegistryKey rootkey = Microsoft.Win32.Registry.LocalMachine;
                Microsoft.Win32.RegistryKey Local = rootkey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
                Local.DeleteValue("wing");
            }
        }