Trouble creating DWORD in LocalMachine registry field with C# WinForms

181 views Asked by At

I am trying to create a DWORD in the LocalMachine registry field using a WinForms (C#) application.

No errors are raised, but the entry is never created.

RegistryKey registryKey;
registryKey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\InetStp\Configuration");
registryKey.SetValue("MaxWebConfigFileSizeInKB", 512, RegistryValueKind.DWord);

Any ideas?

1

There are 1 answers

1
Ludovic Feltz On BEST ANSWER

I had a similar problem before.

With the lasts version of windows you can't write directly to the LocalMachine emplacement due to security concern.

They are no error because the key is created in another emplacement. Did you try searching for your key ? Try to execute your program in Admin mode it may create the key.


Edit:

After some test i found that in Admin mode the key is created in:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB

But in normal user mode i have the following error:

System.UnauthorizedAccessException: Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Configuration' is denied.