Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在.NETCore3.1WPF中运行交互Shell_C#_Wpf_Visual Studio 2019_.net Core 3.1 - Fatal编程技术网

C# 如何在.NETCore3.1WPF中运行交互Shell

C# 如何在.NETCore3.1WPF中运行交互Shell,c#,wpf,visual-studio-2019,.net-core-3.1,C#,Wpf,Visual Studio 2019,.net Core 3.1,我正在尝试运行Shell命令,以在连接或断开vpn时启用或禁用防火墙权限,并且我使用microsoft.visualbasic来启用或禁用防火墙权限,这在Visual studio 2015中运行良好,但现在我在Visual studio 2019.Net Core中以及在使用microsoft.visualbasic时也在做同样的事情将Shell方法中的错误显示为 CS0117“交互”不包含“Shell”的定义 这就是我试图运行的代码 using System; using System.Co

我正在尝试运行Shell命令,以在连接或断开vpn时启用或禁用防火墙权限,并且我使用microsoft.visualbasic来启用或禁用防火墙权限,这在Visual studio 2015中运行良好,但现在我在Visual studio 2019.Net Core中以及在使用microsoft.visualbasic时也在做同样的事情将Shell方法中的错误显示为

CS0117“交互”不包含“Shell”的定义

这就是我试图运行的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.Diagnostics;
using System.Collections;
using CasVPN.Model;
namespace CasVPN.Classes
{
class Global
{
public static void Disable_Network()
    {
        string value = "netsh advfirewall firewall add rule name = Block All Traffic dir =in action = allow port enable = yes remoteip = 5, 46, 48 - 1722, 1724 - 65535,LocalSubnet profile = public";
        Interaction.Shell("cmd.exe /c" + value);
    }
}
}
根据,Interaction.Shell仅在.NETFramework中可用,不属于.NETCore的一部分


您需要将应用程序更改为目标.NET Framework,或使用运行命令的替代方法,如。

1。运行
netsh.exe
2不需要
cmd.exe的实例。您需要使用。首先为什么要使用
Interaction.Shell
?只需使用
Process.Start(值)
进程。启动(“netsh”,“advfirewall-firewall…”)
。每个人都忽略了全局变量的事实,唉。顺便说一句,当您使用Process.Start()时;而且它不工作设置
UseShellExecute=true