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

  • Home
  • SEARCH
  • 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 7490643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:41:33+00:00 2026-05-29T15:41:33+00:00

I’m trying to make a simple program to change IP parameters in C#. I

  • 0

I’m trying to make a simple program to change IP parameters in C#.
I use this code : How can you change Network settings (IP Address, DNS, WINS, Host Name) with code in C#
to perform it, and made my own method :

public void changerip(string adresse, string NIC)
{
    ManagementObjectCollection objMOC = objMC.GetInstances();
    foreach (ManagementObject objMO in objMOC)
    {

        if (objMO["Caption"].Equals(NIC))
        {
            try
            {
                if (adresse != "0")
                {
                    ManagementBaseObject setIP;
                    ManagementBaseObject newIP =
                        objMC.GetMethodParameters("EnableStatic");

                    newIP["IPAddress"] = new string[] { "192.168." + adresse + ".50" };
                    newIP["SubnetMask"] = new string[] { "255.255.255.0" };
                    setIP = objMO.InvokeMethod("EnableStatic", newIP, null);

                    ManagementBaseObject setGateway;
                    ManagementBaseObject newGateway =
                    objMO.GetMethodParameters("SetGateways");
                    newGateway["DefaultIPGateway"] = new string[] { "192.168." + adresse + ".254" };
                    newGateway["GatewayCostMetric"] = new int[] { 1 };
                    setGateway = objMO.InvokeMethod("SetGateways", newGateway, null);

                    ManagementBaseObject newDNS =
                    objMO.GetMethodParameters("SetDNSServerSearchOrder");
                    newDNS["DNSServerSearchOrder"] = "192.168.1.24,192.168.1.2".Split(',');
                    ManagementBaseObject setDNS =
                    objMO.InvokeMethod("SetDNSServerSearchOrder", newDNS, null);
                }
                else
                {
                    ManagementBaseObject newDNS = objMO.GetMethodParameters("SetDNSServerSearchOrder");
                    newDNS["DNSServerSearchOrder"] = null;
                    ManagementBaseObject enableDHCP = objMO.InvokeMethod("EnableDHCP", null, null);
                    ManagementBaseObject setDNS = objMO.InvokeMethod("SetDNSServerSearchOrder", newDNS, null);
                    //Save all Gateways into an array
                    string[] gateways = (string[])objMO["DefaultIPGateway"];

                    ManagementBaseObject newIP = objMO.GetMethodParameters("EnableStatic");
                    ManagementBaseObject newGate = objMO.GetMethodParameters("SetGateways");

                    //Set last value of the array(always the Gateway recived by DHCP) as the default Gateway
                    newGate["DefaultIPGateway"] = new string[] { gateways[gateways.Length - 1] };
                    newGate["GatewayCostMetric"] = new int[] { 1 };
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
    }
}

It works fine in Windows XP, but don’t works on Windows 7 (Starter or Pro). I haven’t any exception rising nor error/security message from the OS.

Someone have an idea of what happened ?

  • 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-29T15:41:34+00:00Added an answer on May 29, 2026 at 3:41 pm

    Looks like a credentials issue to me. You should run the program with Administrative privileges. You can do it by a simple Right click on exe and click “Run as Administrator”.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have this code to decode numeric html entities to the UTF8 equivalent character.
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.