Session ID in PSExec

前端 未结 2 1915
既然无缘
既然无缘 2021-01-14 03:57

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>         


        
2条回答
  •  庸人自扰
    2021-01-14 04:28

    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"
    

提交回复
热议问题