tags:

views:

675

answers:

3

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 great when installing as "Just Me" in the .NET installer however I would like to set these values for all users on the computer (Everyone).

My application is a proxy server that will log all URL requests that it receives. For this to work it requires the proxy values to be setup in Internet Settings. I would like this to happen as part of the install process instead of the admin having to set it for all users.

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

Is there a way to change the mentioned Registry Keys so that all user's IE will have the Prxy settings set?

The code I am currently using 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);
    }
A: 

Adding it to HKEY_USERS wont be enough(?)

Shoban
ok, then what is required? This is a new area for me.
modernzombie
try adding the key to HKEY_USERS than HKEY_CURRENT_USER
Shoban
A: 

Have you tried using Registry.LocalMachine?

http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.localmachine.aspx

TJMonk15
Yes I tried Registry.LocalMachine. The keys were set no problem but IE, even for the current user, ignored it.
modernzombie
Ok this was half of the answer. There was another key that had to be set first (ProxySettingsPerUser).
modernzombie
A: 

I found the answer with help from http://www.pctools.com/guides/registry/detail/1147/.

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

modernzombie