- chameleon_src.zip
- Chameleon
- BusinessObjects
- Chameleon.sln
- Chameleon.vssscc
- ChameleonSetup
- ChameleonSetup.vdproj
- ChameleonSetup.vdproj.vspscc
- Debug
- ChameleonSetup.msi
- setup.exe
- mssccprj.scc
- Release
- vssver2.scc
- ControlLib
- GUI
- Helper
- mssccprj.scc
- vssver2.scc
- chameleon_demo.zip
|
using System;
using System.Collections.Generic;
using System.Text;
using BusinessObjects;
using System.Management;
using System.Data;
namespace GUI
{
public class WMIManager
{
public List<Connection> GetConnections()
{
List<Connection> insListConnection = new List<Connection>();
ManagementObjectSearcher m = new ManagementObjectSearcher();
m.Query = new ObjectQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True");
foreach (ManagementObject mo in m.Get())
{
Connection c = new Connection();
c.ConnectionId = mo["Index"].ToString();
c.ConnectionName = mo["Caption"].ToString().Substring(mo["Caption"].ToString().IndexOf("]") + 1).Trim();
insListConnection.Add(c);
}
return insListConnection;
}
public void SetConnectionProfile(Connection c, Profile p)
{
ManagementObjectSearcher m = new ManagementObjectSearcher();
m.Query = new ObjectQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True");
foreach (ManagementObject mo in m.Get())
{
if (mo["Index"].ToString()==c.ConnectionId)
{
mo.InvokeMethod("EnableStatic", new object[] { new string[] { p.IpAddress }, new string[] { p.SubnetMask } });
mo.InvokeMethod("SetGateways", new object[] { new string[] { p.DefaultGateway }, new string[] { "1" } });
mo.InvokeMethod("SetDNSServerSearchOrder", new object[] { new string[] { p.PreferredDns} });
if (p.ProxyEnabled)
{
RegistryManager.EnableProxy = true;
RegistryManager.BypassProxyForLocalAddresses = p.ByPassProxyForLocal;
RegistryManager.ProxyAddress= p.ProxyAddress + ":" + p.ProxyPort;
}
else
{
RegistryManager.EnableProxy = false;
RegistryManager.ProxyAddress = "";
RegistryManager.BypassProxyForLocalAddresses = true;
}
}
}
}
public void SetConnectionAutomatic(Connection c)
{
ManagementObjectSearcher m = new ManagementObjectSearcher();
m.Query = new ObjectQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True");
foreach (ManagementObject mo in m.Get())
{
if (mo["Index"].ToString() == c.ConnectionId)
{
mo.InvokeMethod("EnableDHCP", null);
mo.InvokeMethod("SetDNSServerSearchOrder", null);
RegistryManager.EnableProxy = false;
RegistryManager.ProxyAddress = "";
RegistryManager.BypassProxyForLocalAddresses = true;
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.