Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET Setup Project - Changing Registry Settings
    primarykey
    data
    text
    <p>I have a class that modifies the ProxyEnable and ProxyServer registry keys of Internet Settings. </p> <p>If I use this class in a Console App and run it the value are changed and I can see the changes using regedit.</p> <p>Now the part that doesn't work is I am trying to use this class in an Installer class so that the registry keys are changed during installation of my application.</p> <p>Here is the code for the class:</p> <pre><code>public class ProxySettings { [DllImport("wininet.dll")] public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength); public const int INTERNET_OPTION_SETTINGS_CHANGED = 39; public const int INTERNET_OPTION_REFRESH = 37; static bool settingsReturn, refreshReturn; public void EnableProxy(string proxy) { 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); } public void DisableProxy() { 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); } } </code></pre> <p>Here is my Installer class:</p> <pre><code>[RunInstaller(true)] public class WindowsServiceInstaller : Installer { public WindowsServiceInstaller() { ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller(); ServiceInstaller serviceInstaller = new ServiceInstaller(); //# Service Account Information serviceProcessInstaller.Account = ServiceAccount.LocalSystem; serviceProcessInstaller.Username = null; serviceProcessInstaller.Password = null; //# Service Information serviceInstaller.DisplayName = "Client Service"; serviceInstaller.StartType = ServiceStartMode.Automatic; //# This must be identical to the WindowsService.ServiceBase name //# set in the constructor of WindowsService.cs serviceInstaller.ServiceName = "Client Service"; this.Installers.Add(serviceProcessInstaller); this.Installers.Add(serviceInstaller); } public override void Commit(System.Collections.IDictionary savedState) { base.Commit(savedState); ServiceController controller = new ServiceController("Client Service"); if(controller.Status != ServiceControllerStatus.Running) { controller.Start(); } ProxySettings proxy = new ProxySettings(); proxy.EnableProxy("127.0.0.1:8889"); } public override void Uninstall(System.Collections.IDictionary savedState) { base.Uninstall(savedState); ProxySettings proxy = new ProxySettings(); proxy.DisableProxy(); } } </code></pre> <p>In the override of Commit I am starting the service which works fine but for some reason I don't see the changes to the registry.</p> <p>Just too make sure the class was initializing and firing I added</p> <pre><code>System.Diagnostics.Process.Start("http://www.microsoft.com"); </code></pre> <p>to both the EnableProxy and DisableProxy methods. During the install the website opened and also during uninstall but the registry remained unchanged.</p> <p>What am I doing wrong? Why will it work running as a Console App but not in an Installer?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload