【问题标题】:Windows - Programatically check if hosted wlan network is possible on system's hardwareWindows - 以编程方式检查系统硬件上是否可以托管 wlan 网络
【发布时间】:2016-12-10 02:48:02
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: c# .net windows wifi


    【解决方案1】:

    您可以从进程的输出流中回读。 当你设置你的过程时,它可能看起来像这样:

    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;
    

    使用此链接获取更多有用的命令: enter link description here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-07
      相关资源
      最近更新 更多