PeterSchenk
asked on
Putting quotes on a statement
Im using the following code and I need to be able to put quotes in the following statement. The proper command to be enter is this
Netsh.exe firewall add portopening TCP 1212 “Add Quotes”
This is the programmatic line im using
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + textBox5.Text;
Just not sure how to add what I need to the input on textBox5
Process p = new Process();
p.StartInfo.UseShellExecut e = false;
p.StartInfo.RedirectStanda rdOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + textBox5.Text;
p.Start();
Netsh.exe firewall add portopening TCP 1212 “Add Quotes”
This is the programmatic line im using
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + textBox5.Text;
Just not sure how to add what I need to the input on textBox5
Process p = new Process();
p.StartInfo.UseShellExecut
p.StartInfo.RedirectStanda
p.StartInfo.CreateNoWindow
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + textBox5.Text;
p.Start();
ASKER
Same issue did not work
put a breakpoint on the line p.Start(); and inspect what the StartInfo.Arguments actually are.
can you show us your code ?
why do you have a / in your string concatenation?
why do you have a / in your string concatenation?
ASKER
Did all that....
Need the qoutes around the name of the port.... which is a textbox.
Netsh.exe firewall add portopening TCP 1212 “Port Name”
Need the qoutes around the name of the port.... which is a textbox.
Netsh.exe firewall add portopening TCP 1212 “Port Name”
ASKER
Here is all the code
private void button3_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(text Box3.Text) || String.IsNullOrEmpty(textB ox5.Text))
{
MessageBox.Show("TCP Port Number and Port Name must be filled in!", "Error");
return;
}
Process p = new Process();
p.StartInfo.UseShellExecut e = false;
p.StartInfo.RedirectStanda rdOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + textBox5.Text;
p.Start();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd ();
p.WaitForExit();
MessageBox.Show(output, "Result");
Application.Exit();
}
private void button3_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(text
{
MessageBox.Show("TCP Port Number and Port Name must be filled in!", "Error");
return;
}
Process p = new Process();
p.StartInfo.UseShellExecut
p.StartInfo.RedirectStanda
p.StartInfo.CreateNoWindow
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + textBox5.Text;
p.Start();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd
p.WaitForExit();
MessageBox.Show(output, "Result");
Application.Exit();
}
What was the value of p.StartInfo.Arguments ?
change:
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + textBox5.Text;
to:
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + Convert.ToChar(34) + textBox5.Text+ Convert.ToChar(34);
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + textBox5.Text;
to:
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + Convert.ToChar(34) + textBox5.Text+ Convert.ToChar(34);
Also why have you got a "/" in the middle of the string you construct when that doesn't appear in what you say you require as a string?
ASKER
emoreua,
If I make that change the string "output" contains the following information
output = "The syntax supplied for this command is not valid. Check help for the correct syntax.\r\n\r\nadd portopening\r\n [ protocol = ] TCP|UDP|ALL \r\n [ port = ] 1-65535 ...
This shows us that its not taking the "" qoutes.
If I make that change the string "output" contains the following information
output = "The syntax supplied for this command is not valid. Check help for the correct syntax.\r\n\r\nadd portopening\r\n [ protocol = ] TCP|UDP|ALL \r\n [ port = ] 1-65535 ...
This shows us that its not taking the "" qoutes.
your syntax is not showing the last parameter. are you sure you can add it?
if you type at dos prompt with that last parameter, does it work?
have you tried to remove the /
if you type at dos prompt with that last parameter, does it work?
have you tried to remove the /
ASKER
Works at the dos prompt.... removing the / does nothing.
and what are you EXACTLY typing at dos prompt?
ASKER
netsh.exe firewall add portopening TCP 1122 "PortName"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That Worked....
Thank you
Thank you
from the beginning we were asking what was that / !
If you had bothered to take note of my very first comment (and its repeat some time later) this problem would have been resolved some hours ago.
string Arguments = "firewall add portopening TCP " + tb3 + "/" + Convert.ToChar(34) + tb5 + Convert.ToChar(34);