C#でICS設定などをする

3 of 41234Next»
固定IPアドレス設定

WMIを使用。ネットで検索すれば沢山情報が見つかります。

[手順]

  1. ManagementObjectSearcher WMIクラスでネットワークデバイスの一覧を取得
  2. 目的のデバイスに対し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 }
        });
    }
}

[参考]

3 of 41234Next»

— posted by mu at 03:13 pm  

この記事に対するコメントはありません

T: Y: ALL: Online:
ThemeSwitch
  • Basic
Created in 0.0157 sec.
prev
2012.10
next
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31