6 Replies - 18121 Views - Last Post: 26 February 2010 - 01:01 PM Rate Topic: -----

#1 MikeAbyss  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 56
  • Joined: 09-July 07

Netsh Interface

Posted 29 November 2007 - 10:12 PM

I'm trying to use
System.Diagnostics.Process.Start("netsh interface ip set address name=\"LAN1\" static 10.0.0.1 255.255.255.0");



What I'm trying to do is create a button that changes the users IP to 10.0.0.1

but it doesn't seem to work, anyone know the correct way of writing it?

The error I get is a runtime error, Win32 Exception was unhanded.

Thanks to all who replies

Is This A Good Question/Topic? 0
  • +

Replies To: Netsh Interface

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Netsh Interface

Posted 29 November 2007 - 10:30 PM

Try putting it into a Try...Catch block and see if it tells you the error:

NOTE: Also, try adding using System.Diagnostics; to the top of your class so you dont have to type all that out.

try
{
	   Process.Start("netsh interface ip set address name=\"LAN1\" static 10.0.0.1 255.255.255.0");
}
catch(Exception ex)
{
	   MessageBox.Show(ex.Message);
}



That should at least get you closer to your error. By the way, why are you writing an application that changes a users IP address?
Was This Post Helpful? 0
  • +
  • -

#3 MikeAbyss  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 56
  • Joined: 09-July 07

Re: Netsh Interface

Posted 29 November 2007 - 10:49 PM

Thanks for the help, haven't got it working yet tho :X "The system cannot find the file specified" and it's for a project at school, I'm suppose to choose 1 other course that I'm currently taking, and use programming with it

E.g I have cisco(Networking) this semester, so I've decide to program an IP changer (Networking + Programming)

This post has been edited by MikeAbyss: 29 November 2007 - 10:49 PM

Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Netsh Interface

Posted 29 November 2007 - 10:54 PM

That error is telling you that you're providing the wrong path to the specified file you're wanting to access
Was This Post Helpful? 0
  • +
  • -

#5 MikeAbyss  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 56
  • Joined: 09-July 07

Re: Netsh Interface

Posted 30 November 2007 - 12:20 AM

Never mind, from what I've read this kind of functionality is still not supported by the framework :(

This post has been edited by MikeAbyss: 30 November 2007 - 12:35 AM

Was This Post Helpful? 0
  • +
  • -

#6 corliss  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 189
  • Joined: 25-October 06

Re: Netsh Interface

Posted 09 December 2007 - 11:06 PM

Yes, But it still can be acheived.
Find the paths that have the currnet ip address and change it. Then refresh the network settings on the device that you are interfacing like the NIC card.
Carry on soldier
Was This Post Helpful? 0
  • +
  • -

#7 Guest_MilWis*


Reputation:

Re: Netsh Interface

Posted 26 February 2010 - 01:01 PM

Here is an snippet of how to add a static address to a NIC using netsh:
// Add address to NIC
Process p = new Process();
            p.StartInfo.FileName = "netsh.exe";

            // Now build the parameters string, which consists of these parameters and identifiers with spaces between each:
            // 1. "interface ip" - context for command
            // 2. "add address" - add an address
            // 3. "name=" - to which adapter to add the address
            // 4. "addr=" - which address to add to the adapter
            // 5. "mask=" - subnet mask of address to add
            // 6. "gateway=" - add the address also as a gateway for the adapter
            // 7. "gwmetric=" - set a metric of one so this gateway is used
            StringBuilder parameters = new StringBuilder();
            parameters.Append(" interface ip add address name=\"").Append(winAdapterDesc);
            parameters.Append("\" addr=").Append(ipAddress);
            parameters.Append(" mask=").Append(mask);
            parameters.Append(" gateway=").Append(ipAddress);
            parameters.Append(" gwmetric=").Append("1");
            p.StartInfo.Arguments = parameters.ToString();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            try
            {
                p.Start();
                p.WaitForExit(30000);
                infoString = p.StandardOutput.ReadToEnd();

// If successful, the output will start with "Ok"
... your code here ...

This post has been edited by JackOfAllTrades: 26 February 2010 - 01:21 PM
Reason for edit:: Added code tags. PLEASE!!! [code]...PUT YOUR CODE IN HERE...[/code]

Was This Post Helpful? 0

Page 1 of 1