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 voi开发者_如何转开发d 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);
}
Adding it to HKEY_USERS
wont be enough(?)
Have you tried using Registry.LocalMachine?
http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.localmachine.aspx
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.
精彩评论