Z
zurg
Hi!
I want to use a working WMI script in VB.Net but I get an error:
''An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll''
That's script from WMI (it works):
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_NetworkAdapter",,48)
For Each objItem in colItems
Wscript.Echo "Net Connection Status: " & objItem.NetConnectionStatus
Next
and in VB.Net(doesn't work - it crashes on ''For Each...'' line):
Module Module1
Public Sub Main()
Dim strComputer As String
Dim objWMIService, colItems, objItem As Object
strComputer = "."
objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter", ,
48)
For Each objItem In colItems
MsgBox("Net Connection Status: " & objItem.NetConnectionStatus)
Next
End Sub
End Module
I want to use a working WMI script in VB.Net but I get an error:
''An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll''
That's script from WMI (it works):
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_NetworkAdapter",,48)
For Each objItem in colItems
Wscript.Echo "Net Connection Status: " & objItem.NetConnectionStatus
Next
and in VB.Net(doesn't work - it crashes on ''For Each...'' line):
Module Module1
Public Sub Main()
Dim strComputer As String
Dim objWMIService, colItems, objItem As Object
strComputer = "."
objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter", ,
48)
For Each objItem In colItems
MsgBox("Net Connection Status: " & objItem.NetConnectionStatus)
Next
End Sub
End Module