【问题标题】:Show connected wifi password C#显示连接的wifi密码C#
【发布时间】:2019-09-23 15:28:04
【问题描述】:

我创建了一个程序,当我复制“WiFi 状态”时,会显示一条带有 SSID 的 Windows 消息并显示单一强度。现在我还想要获取 WiFi 密码的选项,但我不知道该怎么做。因为如果我执行命令wlan show profile "+ s1 +" key = clear ",当我执行命令时他也无法显示密码string s3 = s.Substring (s.IndexOf ("Key Content"));有人可以帮助我

这是我的代码:

if (clipboardText == "wifi status")
{
    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    p.StartInfo.FileName = "netsh.exe";
    p.StartInfo.Arguments = "wlan show interfaces";
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.Start();
    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();

    {
        notifyIcon1.Icon = SystemIcons.Exclamation;
        notifyIcon1.BalloonTipTitle = "";
        notifyIcon1.BalloonTipText = "WIFI verbonden met " + s1 + "  " + "Signaal sterkte " + s2;
        notifyIcon1.BalloonTipIcon = ToolTipIcon.Error;
        notifyIcon1.ShowBalloonTip(1000);
    }
}

【问题讨论】:

  • 据我所知,在 C# 中没有办法做到这一点。但我确实找到了this,这可能会有所帮助。如果它不起作用 - 尝试以管理员身份运行它。
  • 这令人困惑。您正在调用netsh wlan show interfaces,它向您显示网络硬件接口,而不是存储的 WiFi 设置。如果你想要netsh wlan show profile SSID_name key=clear 的输出,那么你应该调用它..?
  • 我的电脑找不到那个命令

标签: c# networking wifi


【解决方案1】:

要使用netsh 工具查看 WiFi 配置文件密码,您必须在管理权限下运行它。

使用这个命令:

netsh wlan show profile <SSID_name> key=clear

添加

p.StartInfo.Verb = "runas";

到您的进程启动配置。

【讨论】:

  • 但是如何在我的 c# 代码中显示 wifi 密码?
  • 我想要关键内容,但我不知道如何在我的 Windows 通知中获取它
【解决方案2】:
 Process processWifi = new Process();
        processWifi.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        processWifi.StartInfo.FileName = "netsh";
        processWifi.StartInfo.Arguments = "wlan show profile";
        processWifi.StartInfo.UseShellExecute = false;
        processWifi.StartInfo.RedirectStandardError = true;
        processWifi.StartInfo.RedirectStandardInput = true;
        processWifi.StartInfo.RedirectStandardOutput = true;
        processWifi.StartInfo.CreateNoWindow = true;
        processWifi.Start();
        string output = processWifi.StandardOutput.ReadToEnd();
        string err = processWifi.StandardError.ReadToEnd();
        processWifi.WaitForExit();
        return output;

【讨论】:

  • 欢迎来到 SO!仅代码的答案通常不如带有解释的答案有用。请解释它的作用以及为什么它是解决问题的好方法。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-19
  • 1970-01-01
  • 2017-11-25
  • 1970-01-01
相关资源
最近更新 更多