Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
The "query user" command is a useful tool in the Windows environment for system administrators who need to manage and monitor user sessions on a remote or local computer. This command provides detailed information about user sessions, including session names, user names, session IDs, states, idle times, and logon times. Understanding how to use the "query user" command can help administrators troubleshoot issues, manage resources, and ensure the security of the system.
Examples:
Basic Usage: To display information about all users who are currently logged on to the system, open the Command Prompt and type:
query user
This command will return a list of all active user sessions on the computer, similar to the following output:
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
johndoe console 1 Active none 10/10/2023 09:00 AM
janedoe rdp-tcp#1 2 Active 00:10 10/10/2023 09:15 AM
Query a Specific User: To query information about a specific user, you can specify the username as an argument. For example:
query user johndoe
This command will return information only about the user "johndoe".
Query User on a Remote Computer:
To query user sessions on a remote computer, use the /server
parameter followed by the name of the remote computer:
query user /server:RemotePCName
Replace RemotePCName
with the actual name of the remote computer. This will display the user sessions on the specified remote machine.
Using PowerShell:
While the query user
command is a CMD utility, you can also achieve similar results using PowerShell. For example, to get the list of users logged into a remote computer, you can use:
Get-WmiObject -Class Win32_LogonSession |
ForEach-Object {
$session = $_
Get-WmiObject -Class Win32_LoggedOnUser |
Where-Object { $_.Dependent -eq $session.__PATH } |
Select-Object @{Name="UserName";Expression={$_.Antecedent -replace '.*Domain="([^"]+)",Name="([^"]+)".*','$1\$2'}},
@{Name="LogonId";Expression={$session.LogonId}},
@{Name="LogonType";Expression={$session.LogonType}}
}
This PowerShell script will provide detailed information about the users logged into the system.