C# Create Values in Registry Local Machine

后端 未结 5 1748
闹比i
闹比i 2020-12-28 15:14

The following code is not working for me:

public bool createRegistry()
{
    if (!registryExists())
    {
        Microsoft.Win32.Registry.LocalMachine.Creat         


        
相关标签:
5条回答
  • 2020-12-28 15:34

    Below code to create key in the registry.

    Microsoft.Win32.RegistryKey key;
    key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Wow6432Node\\Names");
    key.SetValue("Name", "Isabella");
    key.Close();
    
    0 讨论(0)
  • 2020-12-28 15:34

    Set the Premission Check bit to true...

    Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\xelo\\", true);
    

    :)

    0 讨论(0)
  • 2020-12-28 15:36

    Even when admin I don't think you can create new keys off LocalMachine. Make sure that you do

    Registry.LocalMachine.CreateSubKey(@"SOFTWARE\YourCompanyName\SomeNewKey");
    

    and not

    Registry.LocalMachine.CreateSubKey("SomeNewKey");
    
    0 讨论(0)
  • 2020-12-28 15:45

    Well you've got your answer already - I'm guessing you're running on Vista or Windows 7 (or Server 2008) and the process/user running the app doesn't have rights/permission to modify the registry.

    So its not a code problem as such but a systems admin one. Build the app and run as administrator and see if that works.

    0 讨论(0)
  • 2020-12-28 15:50

    Non-admin and unelevated admin users don't have rights to modify the HKEY_LOCAL_MACHINE key. Run the program 'as administrator'.

    0 讨论(0)
提交回复
热议问题