WMIを使用。ネットで検索すれば沢山情報が見つかります。
[手順]
- ManagementObjectSearcher WMIクラスでネットワークデバイスの一覧を取得
- 目的のデバイスに対しEnableStatic()を呼び出す
[メモ]
- ManagementObject.Properties["SettingID"]で得られるGUIがICS設定で使用したGUIDと関連します
using System.Management;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE");
ManagementObjectCollection NICCollection = searcher.Get();
foreach (ManagementObject aNIC in NICCollection)
{
if( aNIC.Properties["SettingID"].Value as string == privateSettingID )
{
aNIC.InvokeMethod("EnableStatic", new object[]
{
new string[] { "192.168.137.1", "192.168.0.1" },
new string[] { "255.255.255.0", "255.255.255.0" }
});
aNIC.InvokeMethod("SetGateways", new object[]
{
new string[] { "192.168.137.1" },
new UInt16[] { 1 }
});
}
}
[参考]















Comments