开机自动运行的方法
using Microsoft.Win32;//Registry的引用空间.
- 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();
- }
- }
版权声明:本文为wf5360308原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。