Registry entry method

work on a window in C #. I want to write on registry.i know how to write on registry.I use the syntax below to write to the registry.

        Microsoft.Win32.RegistryKey key;
        key = Microsoft.Win32.Registry.CurrentUser.cre.CreateSubKey("asb");
        key.SetValue("asb", "Isabella");
        key.Close();

But the problem is that I can not write in the specified place. I want to write below.

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

At this point, add the string value = "abc" and ValueData = "efd" If you have a request plz ask.thanks in advance.

+3
source share
3 answers

For HKCU:

string keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
RegistryKey rk = Registry.CurrentUser.OpenSubKey(keyName, true);
rk.SetValue("abc", "efd");
rk.Close();

For HKLM, you need to do this with administrative privileges. This requires adding a manifest to your program to invoke the UAC prompt on Vista or Win7.

+7
source

HKEY_LOCAL_MACHINE . Windows Vista 7, , UAC (User Account Control).

( ). .

HKEY_CURRENT_USER. Registry.CurrentUser. , , . Visual Studio , #. .

+2
RegistryKey reg = Registry.LocalMachine.
                  OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);

// set value of "abc" to "efd" 
reg.SetValue("abc", "efd", RegistryValueKind.DWord);

// get value of "abc"; return 0 if value not found 
string value = (string)reg.GetValue("abc", "0");
+2
source

All Articles