A
A
Alexander Ivanov2021-08-11 07:16:51
C++ / C#
Alexander Ivanov, 2021-08-11 07:16:51

Why do registry changes only happen once?

There is a code:

RegistryKey myKey = Registry.CurrentUser;
RegistryKey wKey = myKey.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
wKey.SetValue("ProxyServer", proxyhost + ":" + port.ToString());
wKey.SetValue("ProxyEnable", 1);
wKey.Close();
myKey.Close();


it's tied to a mouse click, and what it does is change the system proxy in the browser's properties. So this code works for some reason only once when you start the program, if you select another proxy, then it will not change. If you restart the program and select a proxy, the code will work. Why is this happening and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Glebov, 2021-08-19
@GLeBaTi

Try manually flushing:

RegistryKey wKey = ...
wKey.SetValue(...);
wKey.Flush();
wKey.Close();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question