Dheeraj,
Here's how to do it in VB.NET:
1) Add a reference to the SYSTEM.MANAGEMENT dll
2) Imports System.Management
3) Code (I put behind a button):
Dim moc As ManagementObjectCollection
Dim co As ConnectionOptions = New ConnectionOptions
Dim strComputerName As String = "."
Dim objQuery As ObjectQuery = New ObjectQuery("Select * from
Win32_ComputerSystem")
Dim ms As ManagementScope = New ManagementScope("\\" &
strComputerName & "\root\cimv2", co)
Dim mos As ManagementObjectSearcher = New
ManagementObjectSearcher(ms, objQuery)
Try
moc = mos.Get()
Catch ex As Exception
Console.WriteLine("Error: " + ex.ToString())
End Try
For Each mo As ManagementObject In moc
Console.WriteLine("'{0}' is currently logged on",
mo("Username").ToString())
Next
Will return:
MachineName\UserName
Remember you need to specify 'strComputerName', as '.' makes it point to the
local machine
I hope this helps,
--
Newbie Coder
(It's just a name)
Post by DheerajHi There
Is there anyway of knowing to get the logged user remotely using WMI ?
Thanks
Dheeraj