From b423fef85c1967b0b77ef4776e26e6f6f41f85e3 Mon Sep 17 00:00:00 2001 From: Scott Hanselman Date: Sat, 28 Jan 2017 01:46:17 -0800 Subject: [PATCH] Handlng rare null case Handlng rare null case with managed Wifi Networks. Also added "progress bar" --- WifiProfiles/NetShWlanWrapper.cs | 7 ++++--- WifiProfiles/Program.cs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/WifiProfiles/NetShWlanWrapper.cs b/WifiProfiles/NetShWlanWrapper.cs index f5976bb..c2a0b3f 100644 --- a/WifiProfiles/NetShWlanWrapper.cs +++ b/WifiProfiles/NetShWlanWrapper.cs @@ -31,8 +31,8 @@ public static List GetWifiProfiles() { profiles.Add(new WifiProfile() { Name = x.Descendants(ns + "name").First().Value, - ConnectionMode = x.Descendants(ns + "connectionMode").First().Value, - Authentication = x.Descendants(ns + "authentication").First().Value + ConnectionMode = x.Descendants(ns + "connectionMode").FirstOrDefault()?.Value, + Authentication = x.Descendants(ns + "authentication").FirstOrDefault()?.Value }); } } @@ -62,8 +62,9 @@ private static void ExportAllWifiProfiles() foreach (var match in listOfProfiles) { ExecuteNetSh(String.Format("wlan export profile \"{0}\" folder=\"{1}\"", match.ToString(), Environment.CurrentDirectory)); - + Console.Write("."); } + Console.WriteLine(); } public static void DeleteExportedWifiProfiles() diff --git a/WifiProfiles/Program.cs b/WifiProfiles/Program.cs index 2bccc30..8f0c431 100644 --- a/WifiProfiles/Program.cs +++ b/WifiProfiles/Program.cs @@ -28,7 +28,7 @@ static void List(bool autoDelete) foreach (var a in profiles) { var warning = NetShWrapper.IsOpenAndAutoWifiProfile(a) ? Resources.stringResources.WarningAutoConnect : String.Empty; - Console.WriteLine("{0,-20} {1,10} {2,10} {3,30} ", a.Name, a.ConnectionMode, a.Authentication, warning); + Console.WriteLine("{0,-30} {1,10} {2,10} {3,30} ", a.Name, a.ConnectionMode, a.Authentication, warning); if (!String.IsNullOrWhiteSpace(warning)) badWifiNetworkFound = true; }