I am converting my WMI scripts from vbscript to VB.NET.
This one is use to get current login username from a remote computer :
Dim objWMIService, objComputer As Object
Dim colComputer As Collection
Dim logUsername As String
objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer In colComputer
logUsername = objComputer.UserName
Next
I got error message "Specified cast is not valid." for the red line.
Seems the type of colComputer is wrong. What should be the correct data type if it's not a collection ? I have tried use "ManagementObjectCollection". But doesn't seem work. Could anyone give some idea ?
Thanks.
This one is use to get current login username from a remote computer :
Dim objWMIService, objComputer As Object
Dim colComputer As Collection
Dim logUsername As String
objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer In colComputer
logUsername = objComputer.UserName
Next
I got error message "Specified cast is not valid." for the red line.
Seems the type of colComputer is wrong. What should be the correct data type if it's not a collection ? I have tried use "ManagementObjectCollection". But doesn't seem work. Could anyone give some idea ?
Thanks.