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.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.FileName = "netsh.exe";
            p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + "/" + textBox5.Text;
            p.Start();
PeterSchenkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
you can do something like this:
string Arguments = "firewall add portopening TCP " + tb3 + "/" + Convert.ToChar(34) + tb5 + Convert.ToChar(34);
0
PeterSchenkAuthor Commented:
Same issue did not work
0
AndyAinscowFreelance programmer / ConsultantCommented:
put a breakpoint on the line p.Start(); and inspect what the StartInfo.Arguments actually are.
0
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Éric MoreauSenior .Net ConsultantCommented:
can you show us your code ?

why do you have a / in your string concatenation?
0
PeterSchenkAuthor Commented:
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”

0
PeterSchenkAuthor Commented:
Here is all the code

       private void button3_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBox3.Text) || String.IsNullOrEmpty(textBox5.Text))
            {
                MessageBox.Show("TCP Port Number and Port Name must be filled in!", "Error");
                return;
            }

            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = 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();
        }
0
AndyAinscowFreelance programmer / ConsultantCommented:
What was the value of p.StartInfo.Arguments ?
0
Éric MoreauSenior .Net ConsultantCommented:
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);
0
AndyAinscowFreelance programmer / ConsultantCommented:
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?
0
PeterSchenkAuthor Commented:
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.
0
Éric MoreauSenior .Net ConsultantCommented:
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 /
0
PeterSchenkAuthor Commented:
Works at the dos prompt.... removing the / does nothing.
0
Éric MoreauSenior .Net ConsultantCommented:
and what are you EXACTLY typing at dos prompt?
0
PeterSchenkAuthor Commented:
netsh.exe firewall add portopening TCP 1122 "PortName"
0
Éric MoreauSenior .Net ConsultantCommented:
so it should be:
p.StartInfo.Arguments = "firewall add portopening TCP " + textBox3.Text + " " + Convert.ToChar(34) + textBox5.Text+ Convert.ToChar(34);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PeterSchenkAuthor Commented:
That Worked....

Thank you
0
Éric MoreauSenior .Net ConsultantCommented:
from the beginning we were asking what was that / !
0
AndyAinscowFreelance programmer / ConsultantCommented:
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.  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.