Recently a C/s project customer requirements Start-up function, online find some methods, not useful; Finally, I went to the book, found this code, pro-Test available, WPF environment needs to change the way to get the program directory, WinForm directly available.
1 #regionSet power-on self-boot2 stringStrName = AppDomain.CurrentDomain.BaseDirectory +"AutoRunPro.exe";//get the name of the application to run automatically3 if(! System.IO.File.Exists (StrName))//determine if an application file to run automatically exists4 return;5 stringstrNewName = strname.substring (Strname.lastindexof ("\\") +1);//get application file name, not including path6RegistryKey Registry = Registry.LocalMachine.OpenSubKey ("Software\\microsoft\\windows\\currentversion\\run",true);//retrieves the specified subkey7 if(Registry = =NULL)//If the specified subkey does not exist8Registry = Registry.LocalMachine.CreateSubKey ("Software\\microsoft\\windows\\currentversion\\run");//The specified subkey is created9Registry. SetValue (strNewName, strName);//set a new "key-value pair" for this subkeyTen One if(MessageBox.Show ("Setup Complete") ==DialogResult.OK) A { -Refreshsystem ();//Refresh the System - } the #endregion
1 #regionCancel power-on self-boot2 stringStrName = AppDomain.CurrentDomain.BaseDirectory +"AutoRunPro.exe";//get the name of the application to run automatically3 if(! System.IO.File.Exists (StrName))//determine if the application file to be canceled exists4 return;5 stringstrNewName = strname.substring (Strname.lastindexof ("\\") +1);///get application file name, not including path6RegistryKey Registry = Registry.LocalMachine.OpenSubKey ("Software\\microsoft\\windows\\currentversion\\run",true);//reads the specified subkey7 if(Registry = =NULL)//If the specified subkey does not exist8Registry = Registry.LocalMachine.CreateSubKey ("Software\\microsoft\\windows\\currentversion\\run");//The specified subkey is created9Registry. DeleteValue (strNewName,false);//Remove key/value pairs for the specified key nameTen if(MessageBox.Show ("Setup Complete") ==DialogResult.OK) One { A Refreshsystem (); - } - #endregion
C#/WPF let the program boot automatically