这是有关IP设定的函数(VB),运行时出现类型不匹配错误,可能未作引用,请教如何引用?
Function ChangeIP(IP As String, NM As String, GW As String, MDNS As String, SDNS As String) As String
'返回值说明:返回一个设置的中文说明.
Dim strComputer, objWMIService, colNetAdapters, strIPAddress, strSubnetMask
Dim strGateway, strGatewaymetric, strDNS, objNetAdapter, errEnable, errGateways, errDNS
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array(IP) 'ip地址
strSubnetMask = Array(NM) '子网掩码
strGateway = Array(GW) '网关
strDNS = Array(MDNS, SDNS) '主DNS备DNS
strGatewaymetric = Array(1)
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
If errEnable = 0 And errGateways = 0 And errDNS = 0 Then
ChangeIP = "设置成功"
Else
If errEnable = 0 Then
ChangeIP = "IP地址和子网掩码设置成功, "
Else
ChangeIP = "IP地址或子网掩码设置失败, "
End If
If errGateways = 0 Then
ChangeIP = ChangeIP & "默认网关设置成功, "
Else
ChangeIP = ChangeIP & "默认网关设置失败, "
End If
If errDNS = 0 Then
ChangeIP = ChangeIP & "DNS设置成功"
Else
ChangeIP = ChangeIP & "DNS设置失败"
End If
End If
Next
End Function
Private Sub Command1_Click()
MsgBox ChangeIP("192.168.1.144", "255.255.255.0", "192.168.1.10", "61.128.128.67", "61.128.128.68")
End Sub
[此贴子已经被作者于2005-8-24 7:14:39编辑过] |