Re: Username of who is logged into workstation via remote desktop



Torgeir,

Due to the multiple replies that I got using the script you sent, I have
settled upon the following which seems to work quite well. Thanks for all
your help.

strComputer = "MT-LINCOLN"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

set objEnum = objWMIService.execQuery_
("select __relpath from win32_process where caption = 'explorer.exe'")

' for testing purposes
' WScript.Echo " " & strComputer &_
" was contacted. Attempting to see who is logged in."

If objEnum.Count = 0 then
wscript.echo "No one currently logged in to " & strComputer & "." & VbCrLf
Else
for each obj in objEnum
set outParams = obj.ExecMethod_("GetOwner")
wscript.echo "User: " & outParams.User &_
" is currently logged in on computer " & strComputer & "." & VbCrLf
next
End If


Regards,
Mike Walraven


"Torgeir Bakken (MVP)" wrote:

> Mike Walraven wrote:
>
> > Thanks in advance for any assistance.
> >
> > I am using a WMI script to return who is logged into a remote computer.
> > (Sample code for workstation MT_LINCOLN is below.) However, the
> > objComputer.UserName only returns users logged into the console, not users
> > logged in via remote desktop. Is there a way to query for both?
> >
> Hi,
>
> Assuming WinXP or Win2k3 Server:
>
>
> Run the VBScript below in a command prompt (cmd.exe) with cscript.exe,
> like this:
>
> cscript.exe "c:\some path\some file.vbs"
>
>
> '--------------------8<----------------------
>
> strComputer = "." ' " use "." for local computer
>
> Set objWMI = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>
> Set colSessions = objWMI.ExecQuery _
> ("Select * from Win32_LogonSession Where LogonType = 2 OR LogonType = 10")
>
> If colSessions.Count = 0 Then
> Wscript.Echo "No interactive users found"
> Else
> For Each objSession in colSessions
> If objSession.LogonType = 2 Then
> WScript.Echo "Logon type: Console"
> Else
> WScript.Echo "Logon type: RDP/Terminal Server"
> End If
> Set colList = objWMI.ExecQuery("Associators of " _
> & "{Win32_LogonSession.LogonId=" & objSession.LogonId & "} " _
> & "Where AssocClass=Win32_LoggedOnUser Role=Dependent" )
>
> For Each objItem in colList
> WScript.Echo "User: " & objItem.Name
> WScript.Echo "FullName: " & objItem.FullName
> WScript.Echo "Domain: " & objItem.Domain
> Next
> Wscript.Echo "Session start time: " & objSession.StartTime
> WScript.Echo
> Next
> End If
>
> '--------------------8<----------------------
>
>
> Alternatively:
>
> To obtain a list of logged on users, an option is to parse the output
> of Qwinsta.exe (comes builtin with WinXP and Win2k3 Server).
>
> QWINSTA.EXE /SERVER:MT-LINCOLN
>
> Look for lines with the text "RDP-Tcp#" in it, it will indicate a RDP
> session and the same line will also contain the user account name.
> The session name "console" will give you info about who is logged
> on at the console.
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx
>
.



Relevant Pages

  • Re: Username of who is logged into workstation via remote desktop
    ... sessions - I assume the ones that have happened since the workstation was ... currently logged into either the console or RDP? ... > session and the same line will also contain the user account name. ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.vbscript)
  • Re: Username of who is logged into workstation via remote desktop
    ... I am using a WMI script to return who is logged into a remote computer. ... However, the objComputer.UserName only returns users logged into the console, not users logged in via remote desktop. ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter/default.mspx. ...
    (microsoft.public.scripting.vbscript)
  • Re: XP Consol password
    ... Well now trying to get into the console and ... You might try to reset the local Administrator password with one of the methods ... mentioned here (creating the reset CD/floppy on another computer): ... Microsoft MVP Scripting and WMI, ...
    (microsoft.public.windowsxp.security_admin)
  • Re: How can I display something on a locked console
    ... The MS "Clear Screen Saver" has a problem when another user comes up to the ... console and tries to use it. ... the icon changes to red. ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.win2000.security)
  • Re: Viewing Currently logged users
    ... > This is because you are not logging into the Server and holding a session ... > live like various legacy systems that have the concept of a terminal session ... to reduce the replication time interval a lot). ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windowsxp.security_admin)