我现在正在使用此代码,但它始终会弹出cmd来检索SSID和信号强度,因此我认为必须有另一种方法来实现此目的。
如果有办法,请告诉我。
private void showConnectedID()
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = "wlan show interfaces";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
try
{
string s = p.StandardOutput.ReadToEnd();
string s1 = s.Substring(s.IndexOf("SSID"));
s1 = s1.Substring(s1.IndexOf(":"));
s1 = s1.Substring(2, s1.IndexOf("\n")).Trim();
string s2 = s.Substring(s.IndexOf("Signal"));
s2 = s2.Substring(s2.IndexOf(":"));
s2 = s2.Substring(2, s2.IndexOf("\n")).Trim();
label1.Text = s1;
label4.Text = s2;
p.WaitForExit();
}
catch
{
label1.Text = "Notconnected";
label4.Text = "Notconnected";
}
}