// 设置开机自启动
public void SetAutoStart()
{
try
{
string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rgkRun == null)
{
rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
rgkRun.SetValue("QuanXiLiShi", path); // 名字请自行设置
}
catch
{
Debug.Log(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
}
finally
{
Regeditkey();
}
}
private void Regeditkey()
{
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rgkRun.GetValue("QuanXiLiShi") == null)
{
Debug.Log("自启动为关闭");
}
else
{
Debug.Log("自启动为打开");
}
}