using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.Win32; namespace Config { public partial class frmSetting : Form { public frmSetting() { InitializeComponent(); } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private void btnOK_Click(object sender, EventArgs e) { RegistryKey LMach = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); RegistryKey softwareRun = LMach.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); if (chkAutoRun.Checked == true) { softwareRun.SetValue("ryProcessServer", "\"" + Application.ExecutablePath + "\" q", RegistryValueKind.String); } else { if (softwareRun.GetValue("ryProcessServer") != null) { softwareRun.DeleteValue("ryProcessServer"); } } softwareRun.Close(); LMach.Close(); this.DialogResult = DialogResult.OK; } private void frmSetting_Load(object sender, EventArgs e) { RegistryKey LMach = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); RegistryKey softwareRun = LMach.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); if (softwareRun.GetValue("ryProcessServer", "").ToString() == "\"" + Application.ExecutablePath + "\" q") { chkAutoRun.Checked = true; } else { chkAutoRun.Checked = false; } softwareRun.Close(); LMach.Close(); } } }