1
Answer

passing a selected comboBox string with spaces to CMD.exe

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:
  1. private void button1_Click_1(object sender, EventArgs e)  
  2. {  
  3. label4.Text = IP.ToString();  
  4. string selIP = label4.Text;  
  5. string selected = comboBox1.Text;  
  6. string strCmdText1;  
  7. // string netADAPTER;  
  8. label2.Text = selected;  
  9. strCmdText1 = "/k netsh interface ip set address " + selected + " static " + selIP + " 255.255.255.0 " + comboBox2.Text + "1";  
  10. System.Diagnostics.Process.Start("CMD.exe", strCmdText1);  
  11. }  
Code 2 Also Tried but no luck:
  1. private void button1_Click_1(object sender, EventArgs e)  
  2. {  
  3. label4.Text = IP.ToString();  
  4. string[] str;  
  5. str = comboBox1.Text.Split(' ');  
  6. string categoryId = str[0] +" "+str[1]+" "+str[2];  
  7. string selIP = label4.Text;  
  8. string selected = comboBox1.Text;  
  9. string strCmdText1;  
  10. // string netADAPTER;  
  11. label2.Text = categoryId;  
  12. strCmdText1 = "netsh interface ip set address " + categoryId + " static " + selIP + " 255.255.255.0 " + comboBox2.Text + "1";  
  13. System.Diagnostics.Process.Start("CMD.exe", strCmdText1);  
  14. }  
 
Any Help would be GREATLY appreciated!!!
Answers (1)