Look at the help of RegistryKey, this thing is not complicated, such as:
1, add key plus value
01.string appName = "Poweroffontime";
02.//gets the assembly that executes the method and gets the file path of the assembly (the directory where the assembly is located by the file path)
03.string Thisexecutablepath = System.Reflection.Assembly.GetExecutingAssembly (). Location;
This path in the 04.//software\\microsoft\\windows\\currentversion\\run registry is the boot-initiated path
05.microsoft.win32.registrykey Rkey = +
. Microsoft.Win32.Registry.LocalMachine.CreateSubKey
. ("Software\\microsoft\\windows\\currentversion\\run");
08.rkey.setvalue (AppName, thisexecutablepath);
09.rkey.close ();
The effect is as follows:
2, read the key value
Microsoft.Win32.RegistryKey Rkey =
Microsoft.Win32.Registry.LocalMachine.CreateSubKey
("software\\ Microsoft\\windows\\currentversion\\run ");
String Key = Rkey.getvalue ("Poweroffontime"). ToString ();
This paper url:http://www.bianceng.cn/programming/csharp/201410/45593.htm
The effect is as follows:
3. Create a new file in the registry and add a key value under the folder
String appName = "Poweroffontime";
Gets the assembly that executes the method, and gets the file path of the assembly (the directory where the assembly is located by the file path)
string thisexecutablepath = System.Reflection.Assembly.GetExecutingAssembly (). Location;
RegistryKey src = Registry.LocalMachine.OpenSubKey ("SOFTWARE", true). OpenSubKey ("Microsoft", true). OpenSubKey ("Windows", true). OpenSubKey ("CurrentVersion", true). OpenSubKey ("Run", true);
Write to the registry key (that is, the folder)
RegistryKey red = src. CreateSubKey ("Poweroffontime");
Write the value red in this folder
. SetValue (AppName, Thisexecutablepath);
The effect is as follows:
4, delete key
RegistryKey src = Registry.LocalMachine.OpenSubKey ("SOFTWARE", true). OpenSubKey ("Microsoft", true). OpenSubKey ("Windows", true). OpenSubKey ("CurrentVersion", true). OpenSubKey ("Run", true);
Src. DeleteSubKey ("Poweroffontime");
The effect is as follows:
Note
Modify the registry, especially the boot automatically startup registry The biggest advantage is that when you write small programs, you can automatically perform every day, such as: you want to write a time when the automatic shutdown of the small program ...