176coding
176coding

Reputation: 3069

psexec open a cmd window remotely

My Requirement is as follows:

  1. pc1 is a remote computer, of course I know it's computer name or ip and username and pwd
  2. pc2 is my computer, and I want to open a cmd window in pc1 not on my pc2

Upvotes: 0

Views: 2188

Answers (1)

(Answer in question converted to a community wiki answer.)

The OP wrote:

Solution:

  1. Firstly, you should know the psexec parameter -i, -i is "Run the program so that it interacts with the desktop of the specified session on the remote system. If no session is specified the process runs in the console session." it is about the user sessionID, so I must know which acount is logon pc1, and what's his user sessionID

  2. The very easy way to know his user sessionID is to open windows task manager on pc1 and click the "Users" tab, and the "ID" column is his user sessionID,

  3. So, you get the user sessionID and you use it on pc2, here is the code

    psexec \ip or pc name -u user -p pwd -accepteula -i 2 cmd
    

and you will get a cmd window on pc1

  1. But user sessionID is dynamic, so I write a batch file to get user sessionID

    @echo off
    REM Default sessionID=2
    set sessionID=2
    for /F "tokens=1,2,3,4,5" %%A in ('"query user | find "Active""') DO (
        set sessionID=%%C
    )
    echo %sessionID%
    

Upvotes: 1

Related Questions