Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 571607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:31:31+00:00 2026-05-13T13:31:31+00:00

I have a class that modifies the ProxyEnable and ProxyServer registry keys of Internet

  • 0

I have a class that modifies the ProxyEnable and ProxyServer registry keys of Internet Settings.

If I use this class in a Console App and run it the value are changed and I can see the changes using regedit.

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.

Here is the code for the class:

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);
    }
}

Here is my Installer class:

[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();
    }
}

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.

Just too make sure the class was initializing and firing I added

System.Diagnostics.Process.Start("http://www.microsoft.com");

to both the EnableProxy and DisableProxy methods. During the install the website opened and also during uninstall but the registry remained unchanged.

What am I doing wrong? Why will it work running as a Console App but not in an Installer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:31:31+00:00Added an answer on May 13, 2026 at 1:31 pm

    Okay, I have figured out what was going on.

    I had the installer set to install for Everyone. I tried installing and selecting Just Me and it worked.

    I guess that makes sense since I was setting a registry key for the current user but was installing for everyone. Does this sound right?

    Anyway, I now have some more testing to do to see if the software will function correctly if installed for Just Me. The application is a Windows Service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that I want to use to store properties for another
I have a class that looks like this public class SomeClass { public SomeChildClass[]
I have a class that modifies data via some extension methods. In order to
I have two threads. One invokes the update method of a class that modifies
Ok, so I have a class that modifies the looks for a specific type
I have some code in a reusable class that modifies some types. Here's a
If you have data for a class that will be modified and needs to
I have class that represents users. Users are divided into two groups with different
I have class method that returns a list of employees that I can iterate
I have a class that map objects to objects, but unlike dictionary it maps

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.