/// <summary> /// Get a full network based on the network name. Requires netshell access. /// </summary> /// <param name="name"></param> public WlanNetwork(string name) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Name cannot be empty"); } _name = name; string output = Netshell.NetshellCmd(PrepareCommand(CmdDetail)); try { _interface = parseInterface(output); _allUsers = (String.Equals(getFieldFromOutput(output, "Applied"), "All User Profile", StringComparison.Ordinal)); _version = Int32.Parse(getFieldFromOutput(output, "Version")); _profileType = getFieldFromOutput(output, "Type"); _name = getFieldFromOutput(output, "Name"); _connectWithoutBroadcast = (!String.Equals(getFieldFromOutput(output, "Network broadcast"), "Connect only if this network is broadcasting", StringComparison.Ordinal)); _autoconnect = (String.Equals(getFieldFromOutput(output, "Connection mode"), "Connect automatically", StringComparison.Ordinal)); _autoswitch = (String.Equals(getFieldFromOutput(output, "AutoSwitch"), "Switch to more preferred network if possible", StringComparison.Ordinal)); _macRandomization = (String.Equals(getFieldFromOutput(output, "MAC Randomization"), "Enabled", StringComparison.Ordinal)); _ssidCount = Int32.Parse(getFieldFromOutput(output, "Number of SSIDs")); _ssidName = getFieldFromOutput(output, "SSID name"); _networkType = getFieldFromOutput(output, "Network type"); _radioType = getFieldFromOutput(output, "Radio type"); _authentication = getFieldFromOutput(output, "Authentication"); _cipher = getFieldFromOutput(output, "Cipher"); _securityKey = (String.Equals(getFieldFromOutput(output, "Security key"), "Present", StringComparison.Ordinal)); _cost = getFieldFromOutput(output, "Cost"); _congested = (getFieldFromOutput(output, "Congested") == "Yes"); _approachingLimit = (getFieldFromOutput(output, "Approaching Data Limit") == "Yes"); _overLimit = (getFieldFromOutput(output, "Over Data Limit") == "Yes"); _roaming = (getFieldFromOutput(output, "Roaming") == "Yes"); _costSource = getFieldFromOutput(output, "Cost Source"); } catch (Exception e) { MessageBox.Show( "The application encountered an unexpected error while parsing a network. You can continue using the app, but some profiles may be missing. Please report this error to the developer (\"http://github.com/Bertware/Wlan10/Issues\")\r\n" + "Error details:\r\n" + e.Message + "\r\n" + e.StackTrace + "\r\n\r\n" + output, "Unexpected error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Forget this network /// </summary> public void ForgetNetwork() { Netshell.NetshellCmd(PrepareCommand(CmdDelete)); }
/// <summary> /// Set the priority for this network /// </summary> /// <param name="priority"></param> public void SetPriority(int priority) { Netshell.NetshellCmd(PrepareCommand(CmdUpdate).Replace("<priority>", priority.ToString())); }
/// <summary> /// Set the network key (WEP/WPA/WPA2) for this network /// </summary> /// <param name="key"></param> public void SetKey(string key) { Netshell.NetshellCmd(PrepareCommand(CmdSetKey).Replace("<key>", key)); }