0

I'm using this code now, but it always pops up the cmd to retrieve SSID and signal strength, so I think there must be a another way to do this.

If there is a way please let me know.

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";
    }    
}

my program picture my program  picture this is what happen when i turn it on

  • "another way to do this"...do _what_? This code is _intended_ to open that dialog... what _exactly_ are you trying to achieve? – René Vogt Oct 10 '18 at 07:44
  • i don't want to popup the cmd i want a way to this in silent way – kavindu tissera Oct 10 '18 at 07:45
  • i added a timer to perform this function , when it comes to p.start() it popping up a cmd and i don't want that – kavindu tissera Oct 10 '18 at 07:47
  • Possible duplicate of [C# - How do I access the WLAN signal strength and others?](https://stackoverflow.com/questions/1686715/c-sharp-how-do-i-access-the-wlan-signal-strength-and-others) – Ashkan Mobayen Khiabani Oct 10 '18 at 07:48
  • "this"... so I _guess_ you want to connect to a wlan? or show available wlans? or... please have a look at [ask]. The question as it stands is really unclear. – René Vogt Oct 10 '18 at 07:48
  • sorry about that my English is bad – kavindu tissera Oct 10 '18 at 07:53
  • First, there is no such thing as *internet SSID*, rather *WiFi SSID*. Second, if your device is connected to a wired network (or even—how unthinkable!—not connected at all), your code will fail. Third, a little bit of searching will get you this (https://stackoverflow.com/questions/431755), pointing to this (http://www.codeplex.com/managedwifi); since it is archived and obsolete, you may want this (https://github.com/DigiExam/simplewifi) instead. I did not thoroughly check all this but it should give you a starting point (or three)… – dumetrulo Oct 10 '18 at 08:25
  • Fourth (just my €0.02), that font you used to write *Wi-Fi connection* is fugly… – dumetrulo Oct 10 '18 at 08:30
  • If you didn't get it from the comments, you just need to add `p.StartInfo.CreateNoWindow = true;`. This will prevent the shell window to appear. I would suggest to `Split()` the output string (`s`) using `{":", "\r\n" }` as delimiters, removing the empty entries and `Trim()` the resulting strings. You'll get all the fields in 1 array. In case you opt for an extension library, this one is newer (the source is actually the same): [ManagedNativeWifi](https://github.com/emoacht/ManagedNativeWifi). – Jimi Oct 10 '18 at 10:28
  • Thank you **[Jimi](https://stackoverflow.com/users/7444103/jimi)*** you gave me what i wanted thank you very much – kavindu tissera Oct 10 '18 at 21:27
  • expected answer is `p.StartInfo.CreateNoWindow = true;` thank you again <3 – kavindu tissera Oct 10 '18 at 21:28

0 Answers0