简体   繁体   English

如何使用带有多个括号的Process.Start()命令?

[英]How can I use the Process.Start() command with multiple parenthesis?

Basically, I'm trying to open cmd to execute a command that will modify my firewall. 基本上,我正在尝试打开cmd以执行将修改防火墙的命令。 The only problem is that the line of code requires parenthesis and it doesn't work with the Process.Start() 唯一的问题是代码行需要括号,并且不适用于Process.Start()

Process.Start("cmd", "/c netsh advfirewall firewall set rule name="neter" new enable="no"") Process.Start(“ cmd”,“ / c netsh advfirewall防火墙设置规则名=” neter“ new enable =” no“”)

I get the error "Error 2 Comma, ')', or a valid expression continuation expected." 我收到错误“错误2逗号,')',或预期的有效表达式继续。” on the parenthesis before neter. 在neter之前的括号中。

It is the quotes that are the problem. 问题是引号。 Use "" for each single " in a string. 对字符串中的每个“”使用“”。

Process.Start("cmd", "netsh advfirewall firewall set rule name=""neter"" new enable=""no""")

There is no need to call cmd . 无需调用cmd Call NetSh direct. 直接致电NetSh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM