Automation Error -2147217406获取本机IP地址时报错(代码如下),错误信息 Run-time error -2147217406(800
Automation Error -2147217406
获取本机IP地址时报错(代码如下),错误信息 Run-time error '-2147217406(80041002)': Automation Error
(注:出错的原因及解决方案。有时运行正常有时报错,报错的语句是set那句)
Function GetIP() As String
Dim ComputerName As String
Dim OpSys, OpSysSet As Object
Dim ip As Variant
ComputerName = "localhost"
Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate}//" & ComputerName).ExecQuery("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration")
For Each OpSys In OpSysSet
If TypeName(OpSys.IPAddress) <> "Null" Then
For Each ip In OpSys.IPAddress
GetIP = ip
Exit Function
Next
End If
Next
End Function
[解决办法]
哎....加个异常处理就OK了
