user3565150
user3565150

Reputation: 914

Session ID in PSExec

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>PsExec -u administrator -p force \\135.20.230.160 query session
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
>services                                    0  Disc
 rdp-tcp#0         Administrator             1  Active  rdpwd
 console                                     4  Conn
 rdp-tcp                                 65536  Listen
query exited on 135.20.230.160 with error code 1.

Now, with the above output, what should be the correct command in psexec to run notepad on the IP address?

Upvotes: 4

Views: 17074

Answers (2)

Peter Veg
Peter Veg

Reputation: 51

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"

Upvotes: 1

Randy Rakestraw
Randy Rakestraw

Reputation: 329

If you are just trying to run notepad on the remote machine do the following:

psexec \\135.20.230.160 -u administrator -p force C:\notepad.exe

More info on psexec

Also I am assuming your password is "force" and as a side note you should not put your password online...

If you want to see notepad.exe open on the machine you are connecting to, for example if you are remote connected into that machine while using psexec from another you would use the following

psexec \\135.20.230.160 -u administrator -p force -i 1 C:\notepad.exe

The 1 after the -i is the session number which needs to correspond to the session which you are logged in as.

To find out what session you are currently logged in as open any program and in console type TaskList and find your program and look at the session number.

Upvotes: 8

Related Questions