mirror of
https://github.com/netchx/netch.git
synced 2026-04-01 19:15:09 +08:00
detach find ManagementObject method,Fix ICS checkbox not displaying status correctly
This commit is contained in:
@@ -51,26 +51,23 @@ namespace Netch.Controllers
|
||||
ushort[] gatewayMetric = null;
|
||||
string[] dns = null;
|
||||
|
||||
ManagementObject outboundWmi = null;
|
||||
foreach (ManagementObject mo in moc)
|
||||
var outboundWmi = WMI.GetManagementObjectByDeviceNameOrDefault(Global.Outbound.Adapter.Description);
|
||||
|
||||
if (outboundWmi == null)
|
||||
{
|
||||
if (((string) mo["Caption"]).EndsWith(Global.Outbound.Adapter.Description))
|
||||
{
|
||||
outboundWmi = mo;
|
||||
if (!(dhcpEnabled = (bool) mo["DHCPEnabled"]))
|
||||
{
|
||||
ipAddress = (string[]) mo["IPAddress"];
|
||||
subnetMask = (string[]) mo["IPSubnet"];
|
||||
gateway = (string[]) mo["DefaultIPGateway"];
|
||||
gatewayMetric = (ushort[]) mo["GatewayCostMetric"];
|
||||
dns = (string[]) mo["DNSServerSearchOrder"];
|
||||
return false;
|
||||
}
|
||||
|
||||
ipAddress = new[] {ipAddress[0]};
|
||||
subnetMask = new[] {subnetMask[0]};
|
||||
}
|
||||
if (!(dhcpEnabled = (bool) outboundWmi["DHCPEnabled"]))
|
||||
{
|
||||
ipAddress = (string[]) outboundWmi["IPAddress"];
|
||||
subnetMask = (string[]) outboundWmi["IPSubnet"];
|
||||
gateway = (string[]) outboundWmi["DefaultIPGateway"];
|
||||
gatewayMetric = (ushort[]) outboundWmi["GatewayCostMetric"];
|
||||
dns = (string[]) outboundWmi["DNSServerSearchOrder"];
|
||||
|
||||
break;
|
||||
}
|
||||
ipAddress = new[] {ipAddress[0]};
|
||||
subnetMask = new[] {subnetMask[0]};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -415,7 +415,8 @@ namespace Netch.Forms
|
||||
{
|
||||
if (ICSCheckBox.Checked)
|
||||
{
|
||||
ICSCheckBox.Checked = ICSController.Enable();
|
||||
if (!ICSController.Enabled)
|
||||
ICSCheckBox.Checked = ICSController.Enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
20
Netch/Utils/WMI.cs
Normal file
20
Netch/Utils/WMI.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Management;
|
||||
|
||||
namespace Netch.Utils
|
||||
{
|
||||
static internal class WMI
|
||||
{
|
||||
public static ManagementObject GetManagementObjectByDeviceNameOrDefault(string deviceName)
|
||||
{
|
||||
foreach (ManagementObject mo in new ManagementClass("Win32_NetworkAdapterConfiguration").GetInstances())
|
||||
{
|
||||
if (((string) mo["Caption"]).EndsWith(deviceName))
|
||||
{
|
||||
return mo;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user