-1

We have domain users that use a remote instance of an app through RDP. The app is quite buggy, and their session needs reset frequently. I'd like to build a script that uses psexec from the client to reset the session on the server.

psexec \\server -u user -p pass query session

shows all the sessions

psexec \\server -u user -p pass reset session_id

resets the session based upon the id.

I need a way to reset the session based upon the username, instead of session name or id

1 Answers1

1

Try this combination of commands to get the username and then you can kill the session by id. You will need PsLoggedOn from Windows Sysinternals Here is the a link which explains the commands. How to check who has logged into your system

PSLOGGEDON -L \\remotecomputeror 

PSEXEC \\remotecomputer NET CONFIG WORKSTATION | FIND /I " name "

PSEXEC \\remotecomputer NET NAME

PSEXEC \\remotecomputer NETSH DIAG SHOW COMPUTER /V | FIND /i "username" 

FOR /F %%A IN ('REG Query \\remotecomputer\HKU ˆ| FINDSTR /R /B /C:"HKEY_USERS\\S-1-5-[0-9][0-9]-[0-9-]*$"') DO ( 
FOR /F "tokens=3 delims=\" %%B IN ('REG Query "\\remotecomputer\%%A\Volatile Environment"') DO ( 
SET LoggedinUser=%%B 
) 
) 
SoftwareCarpenter
  • 3,835
  • 3
  • 25
  • 37