Psexec fails to display a notepad GUI on the remote session for me. So, I am trying to get the session id as below:
c:\\Users\\Amitra\\Downloads\\PSTools>
To get session ID I use this batch (sorry it's on a french server) :
C:\Windows\system32>psexec -nobanner \\FRBBL31101 query session
SESSION UTILISATEUR ID ÉTAT TYPE PÉRIPHÉRIQUE
>services 0 Déco
console toto 1 Actif
query exited on FRBBL31101 with error code 1.
What we want is the id (the third tokens) at the line containing the word 'console'
my batch :
rem Enter batch name with computer name after like : MyBatch.cmd Mycomputer
set host=%1
FOR /F "tokens=3 delims= " %%i IN ('psexec -nobanner \\%host% query session ^| findstr "console"') DO set "ID=%%i"