0

I'm working on a application to start a hotspot in windows 10 using C# and netsh. So far it seems to be working just fine but I would like to get some info from as well.

    private void Rfsh_Click(object sender, EventArgs e)
    {
        ProcessStartInfo Netinfo = new ProcessStartInfo("cmd");
        Netinfo.UseShellExecute = false;
        Netinfo.RedirectStandardOutput = true;
        Netinfo.CreateNoWindow = true;
        Netinfo.RedirectStandardInput = true;
        var proc = Process.Start(Netinfo);

        proc.StandardInput.WriteLine("netsh wlan show hostednetwork | findstr -i ssid");
        proc.StandardInput.WriteLine("netsh wlan show hostednetwork | findstr -i status");
        proc.StandardInput.WriteLine("exit");
        string netoutput = proc.StandardOutput.ReadToEnd();
        Rtxt.Text = netoutput;
    }

As you can see from the code above I'm trying to get the ssid and hotspot status to post to Rtxt.txt and it does along with the Microsoft header and the users path.

Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. C:\Users\David\documents\visual studio 2010\Projects\NetShare\NetShare\bin\Debug>netsh wlan show hostednetwork | findstr -i ssid SSID name : "Testing" BSSID : 52:53:49:8c:f8:4f C:\Users\David\documents\visual studio 2010\Projects\NetShare\NetShare\bin\Debug>netsh wlan show hostednetwork | findstr -i status Hosted network status
Status : Started C:\Users\David\documents\visual studio 2010\Projects\NetShare\NetShare\bin\Debug>exit

How would could I go about displaying just the ssid and the status without all the other stuff. I was thinking about saving the output to a text file and pulling just the lines that began with SSID name, BSSID and Status but there has to be a more simpler method.

1 Answers1

1

Based on martheens reply I was able to filter out most of the junk I didn't want to view. By modifying my code to the following

    private void Rfsh_Click(object sender, EventArgs e)
    {
        ProcessStartInfo Netinfo = new ProcessStartInfo("cmd");
        Netinfo.UseShellExecute = false;
        Netinfo.RedirectStandardOutput = true;
        Netinfo.CreateNoWindow = true;
        Netinfo.RedirectStandardInput = true;
        var proc = Process.Start(Netinfo);
        proc.StandardInput.WriteLine("netsh wlan show hostednetwork | findstr -i ssid");
        proc.StandardInput.WriteLine("exit");
        string Netoutput = proc.StandardOutput.ReadToEnd();
        string output = Netoutput;
        string[] Asplit = new string[] { "ssid" };
        string[] AOut = output.Split(Asplit, StringSplitOptions.RemoveEmptyEntries);
        foreach (var items in AOut)
        {
            Rtxt.Text = items;
        }

    }

I was able to filter the output to only show from ssid on. I'm reading up on ends with right now to clean up the rest of the output. But marking this as solved because I pretty much got what I am looking for.