当前位置:首页 > Windows程序 > 正文

winform 程序开机启动

2021-03-28 Windows程序

private void Form1_Load(object sender, EventArgs e)

{

try

{

//程序运行位置

string R_startPath = Application.ExecutablePath;

//对应于HKEY_LOCAL_MACHINE主键

RegistryKey R_local = Registry.LocalMachine;

//开机自动运行

RegistryKey R_run = R_local.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

R_run.SetValue("MyAuto", R_startPath);

R_run.Close();

R_local.Close();

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

Console.WriteLine("开机自动运行!");

}

/// <summary>

/// 开机启动    复选框

/// </summary>

/// <param></param>

/// <param></param>

private void cb_kaiji_CheckedChanged(object sender, EventArgs e)

{

if (cb_kaiji.Checked)

{

//程序运行位置

string R_startPath = Application.ExecutablePath;

//对应于HKEY_LOCAL_MACHINE主键

RegistryKey R_local = Registry.LocalMachine;

//开机自动运行

RegistryKey R_run = R_local.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

R_run.SetValue("MyAuto", R_startPath);

R_run.Close();

R_local.Close();

}

else {

//程序运行位置

string R_startPath = Application.ExecutablePath;

//对应于HKEY_LOCAL_MACHINE主键

RegistryKey R_local = Registry.LocalMachine;

//开机自动运行

RegistryKey R_run = R_local.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

R_run.SetValue("MyAuto", false);

R_run.Close();

R_local.Close();

}

}

推荐:Unity3D保护资源管理文件的AssetBundle包加密!

winform 程序开机启动

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/68832.html