Discussion:
How to get the Currently logged user remotely ?
(too old to reply)
Dheeraj
2007-05-12 19:28:01 UTC
Permalink
Hi There

Is there anyway of knowing to get the logged user remotely using WMI ?

Thanks
Dheeraj
Newbie Coder
2007-05-13 00:07:42 UTC
Permalink
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 Dheeraj
Hi There
Is there anyway of knowing to get the logged user remotely using WMI ?
Thanks
Dheeraj
Continue reading on narkive:
Loading...