DWORD AddIPAddress(
IPAddr Address, // IP address to add
IPMask IpMask, // subnet mask for IP address
DWORD IfIndex, // index of adapter
PULONG NTEContext, // Net Table Entry context
PULONG NTEInstance // Net Table Entry Instance
);
Parameters
Address
[in] Specifies the IP address to add to the adapter.
IpMask
[in] Specifies the subnet mask for the IP address.
IfIndex
[in] Specifies the adapter to which to add the address.
NTEContext
[out] Pointer to a ULONG variable that points to the Net Table Entry (NTE) context for this IP address. The caller can later use this context in a call to DeleteIPAddress.
NTEInstance
[out] Pointer to a ULONG variable that points to the NTE instance for this IP address.
DWORD GetAdapterIndex(
LPWSTR AdapterName, // name of the adapter
PULONG IfIndex // index of the adapter
);
Parameters
AdapterName
[in] Pointer to a Unicode string that specifies the name of the adapter.
IfIndex
[out] Pointer to a ULONG variable that points to the index of the adapter.
DWORD DeleteIPAddress(
ULONG NTEContext // net table entry context
);
Parameters
NTEContext
[in] Specifies the Net Table Entry (NTE) context for the IP address. This context was returned by the previous call to AddIPAddress.
WQL = "winmgmts:Win32_NetworkAdapterConfiguration=" & Adapter.DeviceID
Set NIC = GetObject(WQL)
RetVal = NIC.EnableStatic(ipaddr, subnet)
If RetVal = 0 Then
MsgBox "Static IP Enabled"
Else
MsgBox "Static IP Failed"
End If
Next
End Sub
详细信息请参考:
EnableStatic Method in Class Win32_NetworkAdapterConfiguration
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/enablestatic_method_in_class_win32_networkadapterconfiguration.asp