Click here to Skip to main content
15,923,120 members
Home / Discussions / C#
   

C#

 
GeneralRe: FileSystemWatcher and Threading Pin
JoeRip20-Dec-07 1:40
JoeRip20-Dec-07 1:40 
GeneralRe: FileSystemWatcher and Threading Pin
#realJSOP20-Dec-07 2:37
professional#realJSOP20-Dec-07 2:37 
GeneralRe: FileSystemWatcher and Threading Pin
JoeRip20-Dec-07 1:42
JoeRip20-Dec-07 1:42 
GeneralProblems with CSV file blowing out memory Pin
LongRange.Shooter19-Dec-07 11:05
LongRange.Shooter19-Dec-07 11:05 
GeneralRe: Problems with CSV file blowing out memory Pin
Ed.Poore19-Dec-07 11:19
Ed.Poore19-Dec-07 11:19 
GeneralRe: Problems with CSV file blowing out memory Pin
LongRange.Shooter19-Dec-07 13:53
LongRange.Shooter19-Dec-07 13:53 
GeneralRe: Problems with CSV file blowing out memory Pin
Skippums19-Dec-07 12:39
Skippums19-Dec-07 12:39 
Generalrandom files with different date Pin
Shani Aulakh19-Dec-07 9:09
Shani Aulakh19-Dec-07 9:09 
GeneralRe: random files with different date Pin
pmarfleet19-Dec-07 9:20
pmarfleet19-Dec-07 9:20 
GeneralRe: random files with different date Pin
Anthony Mushrow19-Dec-07 9:48
professionalAnthony Mushrow19-Dec-07 9:48 
GeneralRe: random files with different date Pin
pmarfleet19-Dec-07 9:58
pmarfleet19-Dec-07 9:58 
GeneralRe: random files with different date Pin
Shani Aulakh19-Dec-07 17:50
Shani Aulakh19-Dec-07 17:50 
GeneralRe: random files with different date Pin
Dave Kreskowiak20-Dec-07 8:57
mveDave Kreskowiak20-Dec-07 8:57 
GeneralRe: random files with different date Pin
pmarfleet20-Dec-07 9:14
pmarfleet20-Dec-07 9:14 
GeneralRe: random files with different date Pin
Dave Kreskowiak20-Dec-07 15:56
mveDave Kreskowiak20-Dec-07 15:56 
GeneralRe: random files with different date Pin
pmarfleet20-Dec-07 21:16
pmarfleet20-Dec-07 21:16 
GeneralWCF ASMX Web Service Client with HTTP Compression woes Pin
martin_hughes19-Dec-07 9:03
martin_hughes19-Dec-07 9:03 
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

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.