2013-07-30 25 views

回答

2

您想對要配置的網絡接口的Win32_NetworkAdapterConfiguration WMI類實例調用EnableStatic方法。

uint32 EnableStatic(
    [in] string IPAddress[], 
    [in] string SubnetMask[] 
); 

你可以在上面看到它有兩個參數。 IP地址的字符串數組和子網掩碼的字符串數組。

它會返回一個狀態碼。 0表示成功。

下面是PowerShell的示例代碼:

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=true" | 
    ForEach-Object { 
     $result = $_.EnableStatic(("192.168.1.10","10.0.0.10"),("255.255.255.0","255.0.0.0")) 
     if ($result -ne 0) { 
      # handle non-successful response code here. 
     } 
    }