The registry does not change using C # application

Hi guys, I have the following code that works in a windows service.

the service monitors the local network and accordingly changes the proxy server settings, the problem is that for some reason the proxy server settings are not updated.

the application runs under the local system account, but the registry does not change:

Does anyone have any ideas?

using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true))
{
    if (key != null)
    {
        key.SetValue("ProxyEnable", Convert.ToInt32(enable), RegistryValueKind.DWord);

        //I/O Flushes
        key.Flush();
        key.Close();
        return;
    }

    //Exception thrown here to test if key is valid.
}
+3
source share
2 answers

If you work in a local system account, then there is no HKEY_Current_User.

, , , HKEY_CURRENT_USER , Windows- โ€‹โ€‹- โ€‹โ€‹ , .

, , COM-, .

HKEY_LOCAL_MACHINE.

Edit ( , ), RegOpenCurrentUser , RegistryKey. FromHandle .Net API.

+4

, #. .

  • F11-stepping ? , , ? ?

  • SetValue , ?

  • , ?

  • Windows ? , .

:

- . , 3 - . , ?

( F11).

0
source

All Articles