C#.net Form set/Cancel boot automatically run, determine whether the program has been set to boot automatically start (reprint)

Source: Internet
Author: User

#region//Auto-run on boot
private void Cb_auto_checkedchanged (object sender, EventArgs e)
{//cb_auto is a checkbox,isautorun is a Boolean variable that controls whether the boot runs
if (cb_auto.checked = = true) Isautorun = true;
else Isautorun = false;
Try
{
AutoRun ();
}
Catch
{ }
}
private void AutoRun ()
{
Gets the program execution path:
string staruppath = Application.executablepath;
Class Micosoft.Win32.RegistryKey. Represents an item-level node in the window registry, which is a registry-mounted form.
RegistryKey Loca = registry.localmachine;
RegistryKey run = Loca. CreateSubKey (@ "SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

Try
{
SetValue: The name of the stored value
if (Isautorun = = False) run. SetValue ("WinForm", false);//Cancel boot Run
else run. SetValue ("WinForm", staruppath);//Set boot run
Loca. Close ();
}
Catch
{}

}
#endregion

Determine if the program has been set to boot automatically, write in Form_Load

RegistryKey Loca_chek = registry.localmachine;
RegistryKey Run_check = Loca_chek. CreateSubKey (@ "SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
if (Run_check.getvalue ("WinForm"). ToString (). ToLower ()! = "false")
{/respectively/corresponds to the above WinForm and false
Cb_auto.checked = true;
}
Else
{
cb_auto.checked = false;
}

C#.net Form set/Cancel boot automatically run, determine whether the program has been set to boot automatically start (reprint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.