andresleon
Member
- Joined
- Jun 22, 2005
- Messages
- 9
- Programming Experience
- 1-3
i am trying to get the username from a user logged in to a remote machine. I am trying to use wmi to obtain such info in the following sub:
the problem is that when i reach the following line:
i get the following error:
An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll
Additional information: Invalid parameter
i think the problem is how i have constructed the winmgmts path, but all examples i have found follow this same patter. Can someone shed some light on this issue?
Thank you!
VB.NET:
[size=2][color=#0000ff]Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] btnGetUserName_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) _
[/size][size=2][color=#0000ff]Handles[/color][/size][size=2] btnGetUserName.Click
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] objWMIService [/size][size=2][color=#0000ff]As[/color][/size][size=2] Management.ManagementObject
[/size][size=2][color=#008000]
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] strPath [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2] = "WinMgmts:" & _
"{impersonationLevel=impersonate}\\" & txtComputerName.Text & "\root\cimv2"
objWMIService = [/size][size=2][color=#0000ff]New[/color][/size][size=2] ManagementObject(strPath)
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] colComputer [/size][size=2][color=#0000ff]As[/color][/size][size=2] Management.ManagementQuery
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] selectQuery [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] SelectQuery("Select * from Win32_ComputerSystem")
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] searcher [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] ManagementObjectSearcher(selectQuery)
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] mgmObject [/size][size=2][color=#0000ff]As[/color][/size][size=2] ManagementObject
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] strUserName [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] strCompName [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
[/color][/size][size=2][color=#0000ff]For[/color][/size][size=2][color=#0000ff]Each[/color][/size][size=2] mgmObject [/size][size=2][color=#0000ff]In[/color][/size][size=2] searcher.Get()
strUserName = mgmObject("UserName").ToString()
strCompName = mgmObject("name").ToString
[/size][size=2][color=#0000ff]Next[/color][/size][size=2] mgmObject
txt1.Text = strUserName
MsgBox("Done")
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
[/color][/size]
the problem is that when i reach the following line:
VB.NET:
Dim searcher As New ManagementObjectSearcher(selectQuery)
An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll
Additional information: Invalid parameter
i think the problem is how i have constructed the winmgmts path, but all examples i have found follow this same patter. Can someone shed some light on this issue?
Thank you!