locked
Writing value to the registry RRS feed

  • Question

  • iam trying to write a value to the registry and is not leting me could any body help me

    try
                            {
                                RegistryPermission permit = new RegistryPermission( RegistryPermissionAccess.AllAccess  , @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
                                permit.Demand();
                                RegistryKey reg = Registry.CurrentUser;
                                reg = reg.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
                                reg.SetValue("NoDrive", "1", RegistryValueKind.DWord);
                                reg.Close();
                               
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show(e.Message);
                            }
    Saturday, August 9, 2008 7:44 PM

Answers

  • This code works for me:

    Microsoft.Win32.RegistryKey  reg = Microsoft.Win32.Registry.OpenSubKey([keypath], true);

    reg.SetValue([value name], value)

    the key path is the path to the location in the registry were the value will be stored.  the value name is the name of the item at the desired key, and the value is the value that actually want to store.

    Hope this helps.
    There are 10 types of people in this world, those who understand Binary, and those who don't.
    • Marked as answer by ROOT-MIKE Sunday, August 10, 2008 11:15 PM
    Sunday, August 10, 2008 3:35 AM

All replies

  • This code works for me:

    Microsoft.Win32.RegistryKey  reg = Microsoft.Win32.Registry.OpenSubKey([keypath], true);

    reg.SetValue([value name], value)

    the key path is the path to the location in the registry were the value will be stored.  the value name is the name of the item at the desired key, and the value is the value that actually want to store.

    Hope this helps.
    There are 10 types of people in this world, those who understand Binary, and those who don't.
    • Marked as answer by ROOT-MIKE Sunday, August 10, 2008 11:15 PM
    Sunday, August 10, 2008 3:35 AM
  • thanks men yeah all i was missing was the true value, thanks buddy
    Programming Best of Best
    Sunday, August 10, 2008 11:16 PM