我曾经在VB.net中创建了一个小工具来启用/禁用我的以太网。
现在我正在尝试在C#中重新创建它,但我似乎无法弄清楚如何让命令工作。
以下是错误,可能是因为我对C#毫无头绪。
private void btnDisabled_Click(object sender, EventArgs e)
{
Process.Start("CMD", "netsh interface set interface "Ethernet" DISABLED");
}
应该进入netsh接口设置接口"以太网"在命令提示符下禁用。
我显然有完整的代码错误,但我无法知道它应该如何。
有人有任何建议吗?
由于
答案 0 :(得分:2)
你可以测试一下。
ENABLE
feature_names.sort()TypeError: unorderable types: tuple() < str()
DISABLE
static void Enable(string interfaceName)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("netsh", String.Format("interface set interface {0} enable", interfaceName ));
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}
在一种方法中。
static void Disable(string interfaceName)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("netsh", String.Format("interface set interface {0} disable", interfaceName ));
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}
答案 1 :(得分:0)
我认为以下答案应该有助Why does Process.Start("cmd.exe", process); not work?。您可能还需要使用管理员权限执行该流程(请参阅How to start a Process as administrator mode in C#)
答案 2 :(得分:0)
您没有输入它输出的错误,但从阅读上述内容看起来,您似乎正在推出以太网&#34;正在转义您的字符串并且它试图访问以太网对象而不是发送到命令行。如果你想在一个字符串中传递引号,你可以把\&#34;而不是&#34;。