Click here to Skip to main content
15,905,967 members
Home / Discussions / C#
   

C#

 
GeneralReg:Change Text on DataGridViewLinkColumn Pin
P.T.R.K19-Dec-07 8:37
P.T.R.K19-Dec-07 8:37 
GeneralSimple File Counting Pin
ffowler19-Dec-07 8:20
ffowler19-Dec-07 8:20 
GeneralRe: Simple File Counting Pin
Giorgi Dalakishvili19-Dec-07 8:24
mentorGiorgi Dalakishvili19-Dec-07 8:24 
GeneralRe: Simple File Counting Pin
Jimmanuel19-Dec-07 8:24
Jimmanuel19-Dec-07 8:24 
GeneralRe: Simple File Counting Pin
ffowler19-Dec-07 8:26
ffowler19-Dec-07 8:26 
GeneralListView Pin
half-life19-Dec-07 7:30
half-life19-Dec-07 7:30 
GeneralRe: ListView Pin
mav.northwind19-Dec-07 9:13
mav.northwind19-Dec-07 9:13 
NewsSwitching internet connections Pin
new2pgrmg19-Dec-07 6:54
new2pgrmg19-Dec-07 6:54 
Hi all,

I have devoloped an appliction which will set my internet settings.
I have listbox,textbox etc.
The basic idea is that in a button click event the settings that i see in my text boxes should get applied to my computer.

it takes the values from a xml file.
now i am at a point where it displays all the values.


Now i want it get applied on my computer so that on a button clck i can switch between two of my service providers.

So i need help in knowing "how can i make the settings that is in my text box to get applied to my computer so that on a button click i can switch the internet connections".

May be if i show you my code it will be better


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Net;
using System.Diagnostics;
using System.Threading;



namespace InternetApp
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}
XmlTextReader xmltxtRdr = new XmlTextReader("XMLFile1.xml");

private void btnSwitch_Click(object sender, EventArgs e)
{
Process netshobj = new Process();

netshobj.StartInfo.FileName = "netsh";
netshobj.StartInfo.CreateNoWindow = true;

netshobj.ErrorDataReceived += new DataReceivedEventHandler(netshobj_ErrorDataReceived);
//netshobj.StartInfo.Arguments = "netsh";

// Here i tried these to check whether it will work or not and the result is that it shows a netsh window and tahts it.My settings are nit changing//

netshobj.StartInfo.Arguments = "interface ip set dns 'Local Area Connection' static 192.168.1.255 primary";
try
{
netshobj.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

void netshobj_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
MessageBox.Show("The method or operation is not implemented.");
}

private void lstProvider_SelectedIndexChanged(object sender, EventArgs e)
{
GetConnctionSettings( lstProvider.Text);
}

private void GetConnctionSettings(string provider)
{
XmlTextReader xmlTxtRdr = new XmlTextReader("XMLFile1.xml");
while (xmlTxtRdr.Read())
{
if (xmlTxtRdr.Name.ToString() == "connectionName")
{
if (xmlTxtRdr.ReadString().Equals(provider))
{
xmlTxtRdr.ReadToNextSibling("SubNetMask");
txtSubnet1.Text = xmlTxtRdr.ReadString();

xmlTxtRdr.ReadToNextSibling("DefaultGateway");
txtDefaultgateway.Text = xmlTxtRdr.ReadString();

xmlTxtRdr.ReadToNextSibling("DNS1");
txtPrimarydns.Text = xmlTxtRdr.ReadString();


xmlTxtRdr.ReadToNextSibling("DNS2");
txtSecondarydns1.Text = xmlTxtRdr.ReadString();

xmlTxtRdr.ReadToNextSibling("DNS3");
txtSecondarydns2.Text = xmlTxtRdr.ReadString();
GetIP();




}
}
}
}

public void GetIP()
{

string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
//MessageBox.Show(strHostName);
IPAddress[] addr = ipEntry.AddressList;
//MessageBox.Show(addr[0].ToString());
txtSubnet2.Text = (addr[0].ToString());


//return addr[addr.Length-1].ToString();



}

private void Form1_Load(object sender, EventArgs e)
{
try
{
//Load connection names to list box.
getConnectionNamestoListBox();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void getConnectionNamestoListBox()
{

while (xmltxtRdr.Read())
{
if (xmltxtRdr.Name.ToString() == "connectionName")
{
lstProvider.Items.Add(xmltxtRdr.ReadString());
}
}
}

private void groupBox2_Enter(object sender, EventArgs e)
{

}

private void btnCancel_Click(object sender, EventArgs e)
{
MessageBox.Show("You are about to quit Internet Switcher ");
this.Close();
}
}
}


Thanking You
j
GeneralWebPart only renders ok calling CreateChildControl manually Pin
harleydk19-Dec-07 6:33
harleydk19-Dec-07 6:33 
GeneralIs I can fire events using delegated method using "events and delegates" Pin
nallanch_srinivas19-Dec-07 6:24
nallanch_srinivas19-Dec-07 6:24 
GeneralRe: Is I can fire events using delegated method using "events and delegates" Pin
Nathan Holt at EMOM19-Dec-07 11:47
Nathan Holt at EMOM19-Dec-07 11:47 
Generalbuild a C# project in Release & Debug (same out put directory) Pin
kaminem19-Dec-07 5:30
kaminem19-Dec-07 5:30 
GeneralRe: build a C# project in Release & Debug (same out put directory) Pin
darkelv19-Dec-07 6:11
darkelv19-Dec-07 6:11 
Generalhyperlink on a desktop app. Pin
s3rro19-Dec-07 5:02
s3rro19-Dec-07 5:02 
GeneralRe: hyperlink on a desktop app. Pin
DaveyM6919-Dec-07 5:23
professionalDaveyM6919-Dec-07 5:23 
GeneralRe: hyperlink on a desktop app. Pin
Anthony Mushrow19-Dec-07 7:31
professionalAnthony Mushrow19-Dec-07 7:31 
GeneralHandling keystrokes Pin
jesarg19-Dec-07 4:44
jesarg19-Dec-07 4:44 
GeneralRe: Handling keystrokes Pin
Luc Pattyn19-Dec-07 5:15
sitebuilderLuc Pattyn19-Dec-07 5:15 
GeneralRe: Handling keystrokes Pin
jesarg19-Dec-07 10:12
jesarg19-Dec-07 10:12 
GeneralPropertyGrid Pin
netJP12L19-Dec-07 4:27
netJP12L19-Dec-07 4:27 
GeneralRe: PropertyGrid Pin
TJoe19-Dec-07 5:30
TJoe19-Dec-07 5:30 
GeneralRe: PropertyGrid Pin
netJP12L19-Dec-07 5:37
netJP12L19-Dec-07 5:37 
AnswerRe: PropertyGrid Pin
TJoe19-Dec-07 6:05
TJoe19-Dec-07 6:05 
GeneralRe: PropertyGrid Pin
netJP12L19-Dec-07 6:58
netJP12L19-Dec-07 6:58 
AnswerRe: PropertyGrid Pin
TJoe20-Dec-07 3:00
TJoe20-Dec-07 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.