remoteUser = ConsoleUser(“WorkstationNameHere”)
if remoteUser = “” then
msgbox “No User is Logged in”
else
msgbox remoteUser & ” is logged in”
end if
Function ConsoleUser(remoteHost)
‘ Returns name of user logged on to console
‘ If no users are logged on, returns “”
Dim oWMI, colProc, oProcess, remoteUser, sDomain
Set oWmi = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate,(debug)}!\\” _
& remoteHost & “\root\cimv2”)
Set colProc = oWmi.ExecQuery(“Select Name from Win32_Process” _
& ” Where Name=’explorer.exe’ and SessionID=1″)
ConsoleUser = “”
For Each oProcess In colProc
lRet = oProcess.GetOwner(remoteUser, sDomain)
If lRet = 0 Then
ConsoleUser = remoteUser
End If
Next
End Function