private void SetStartup2()
{
try
{
string keys =
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run";
string value = "CopyThat";
if (startWithWindowsCheckBox.Checked)
{
if (Registry.GetValue(keys, value, null) == null)
{
// if key doesn't exist
using (RegistryKey key =
Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.SetValue("CopyThat", (Application.ExecutablePath));
key.Dispose();
key.Flush();
}
}
}
else
{
if (Registry.GetValue(keys, value, null) != null)
{
// if key doesn't exist
using (RegistryKey key =
Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.DeleteValue("CopyThat", false);
key.Dispose();
key.Flush();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void SetStartup2()
{
try
{
string keys =
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run";
string value = "CopyThat";
if (startWithWindowsCheckBox.Checked)
{
if (Registry.GetValue(keys, value, null) == null)
{
// if key doesn't exist
using (RegistryKey key =
Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.SetValue("CopyThat", (Application.ExecutablePath));
key.Dispose();
key.Flush();
}
}
}
else
{
if (Registry.GetValue(keys, value, null) != null)
{
// if key doesn't exist
using (RegistryKey key =
Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.DeleteValue("CopyThat", false);
key.Dispose();
key.Flush();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}