Windows - 以编程方式检查系统硬件上是否可以托管 wlan 网络

Windows - Programatically check if hosted wlan network is possible on system's hardware

我正在寻找一种方法来检查 WLAN 托管网络(也就是设置 AP 而不是连接到网络)功能在系统上是否可用。

目前我正在调用 netsh wlan start hostednetwork 命令来设置它,但该命令的输出太出乎意料,无法真正以编程方式检查它(取决于 windows 语言环境等)。另外,我想在调用此命令之前获得信息。

我认为如果系统上没有 WLAN 设备或硬件不支持托管网络模式,netsh wlan set hostednetwork mode=allow 可能会给出非零退出状态,但似乎 return 总是为零(给定正确的语法)。

我需要实现它的程序是用 C# 编写的,因此任何 .NET 或 P/Invoke 解决方案都应该没问题。

我也在某种程度上使用了ManagedWifi API,但是在那里找不到我的问题的解决方案。

您可以从进程的输出流中读回。 当你设置你正在处理它可能看起来像这样:

ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
processStartInfo.RedirectStandardInput = true; 
processStartInfo.RedirectStandardOutput = true; 
processStartInfo.CreateNoWindow = true; 
processStartInfo.UseShellExecute = false; 
Process process = Process.Start(processStartInfo); 

然后通过命令检查是否支持托管网络:

process.StandardInput.WriteLine("netsh wlan show drivers");
process.StandardInput.Close();

确保关闭输入,否则程序会挂起

现在,如果这是一个命令提示符,你可能会有这样的东西

然后只读输出

            string[] Lines = process.StandardOutput.ReadToEnd().Split("\r\n".ToCharArray());
        string LineString = string.Empty;
        for (int i = 0; i < Lines.Length; i++)
        {
            LineString = Lines[i];
            if (LineString.Contains("Hosted network supported") && LineString.Split(":".ToCharArray())[1].Trim() == "Yes")  return true;
        }
        return false;

使用此 link 以获得更多有用的命令: enter link description here