gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 10:21:22 25 4
gpt4 key购买 nike

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

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

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

我需要在其中实现它的程序是用 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();

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

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

然后只读输出

            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

关于c# - Windows - 以编程方式检查系统硬件上是否可以托管 wlan 网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28498628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com