Setting up a registry key for all users in C #

I have an application that changes some registry values ​​during installation.

I am changing ProxyEnable and ProxyServer in HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet Settings.

This works fine when installed as "Just Me" in the .NET installer, but I would like to set these values ​​for all users on the computer (Everyone).

My application is a proxy server that will log all the URL requests it receives. This requires that the proxy server settings are configured in the Internet settings. I would like this to happen as part of the installation process, rather than having the administrator install it for all users.

I know that this can be done using Group Policy, but some machines that will use this application will have multiple users, not Group Policy (XP Home, etc.).

Is there a way to change the mentioned registry keys so that all user IEs set Prxy settings?

The code I use is:

    private void EnableProxy(string proxy) {
        using(RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true)) {
            registry.SetValue("ProxyEnable", 1);
            registry.SetValue("ProxyServer", proxy);
        }

        settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED,
            IntPtr.Zero, 0);
        refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
    }

    private void DisableProxy() {
        using(RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true)) {
            registry.SetValue("ProxyEnable", 0);
            registry.DeleteValue("ProxyServer", false);
        }

        settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED,
            IntPtr.Zero, 0);
        refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
    }
+1
source share
3 answers

I found the answer using http://www.pctools.com/guides/registry/detail/1147/ .

I needed to create a ProxySettingsPerUser and set it to 0, and then set ProxyEnable and ProxyServer for LocalMachine.

0
source

Adding it to HKEY_USERSwill not be enough (?)

0
source

Source: https://habr.com/ru/post/1705634/


All Articles