Please help - passing a selected comboBox string with spaces to CMD.exe !!
I am making a "QUICK IP CHANGER" program
Trying to change the IP of the Network Adapter named "Local Area Connection"
If I rename the Adapter WITHOUT SPACES "LocalAreaConnection" it works great!!
but when I try to use it with spaces ("Local Area Connection") it doesn't work!
I can't figure out how to pass the selected comboBox1 string to CMD.exe with Spaces in between
This is what i have tried SO FAR ......
Code1:
- private void button1_Click_1(object sender, EventArgs e)
- {
- label4.Text = IP.ToString();
- string selIP = label4.Text;
- string selected = comboBox1.Text;
- string strCmdText1;
-
- label2.Text = selected;
- strCmdText1 = "/k netsh interface ip set address " + selected + " static " + selIP + " 255.255.255.0 " + comboBox2.Text + "1";
- System.Diagnostics.Process.Start("CMD.exe", strCmdText1);
- }
Code 2 Also Tried but no luck:
- private void button1_Click_1(object sender, EventArgs e)
- {
- label4.Text = IP.ToString();
- string[] str;
- str = comboBox1.Text.Split(' ');
- string categoryId = str[0] +" "+str[1]+" "+str[2];
- string selIP = label4.Text;
- string selected = comboBox1.Text;
- string strCmdText1;
-
- label2.Text = categoryId;
- strCmdText1 = "netsh interface ip set address " + categoryId + " static " + selIP + " 255.255.255.0 " + comboBox2.Text + "1";
- System.Diagnostics.Process.Start("CMD.exe", strCmdText1);
- }
Any Help would be GREATLY appreciated!!!