1

In a batch file residing in a remote desktop I have simply written "python jwRelay.py"

I want to run the batch file using psexec using the following command:

psexec -s -i 2 \\135.20.230.160 -u administrator -p force cmd.exe /c "C:\Users\Administrator\Desktop\jwRelayCDV16\SampleCode\Python\relay.bat"

The issue is when I run the above command the command prompt in the remote machine quickly pops up and closes (I can see through mstsc). How can I keep the command prompt open if I want to debug the code remotely?

In my laptop after running the above command I get this:

PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com

cmd.exe exited on 135.24.237.167 with error code 2.

Is there any other alternative than running the script jwRelay.py in interactive mode in the remote machine?

4
  • 2
    If you want the cmd shell to remain open, then use "/k" instead of "/c", e.g. psexec -s -i 2 \\135.20.230.160 cmd.exe /k python path\to\jwRelay.py. If you also want Python to remain open in an interactive shell, use python -i path\to\jwRelay.py. Also, the "-u" option will be ignored considering "-s" makes it run as SYSTEM. Commented Feb 4, 2015 at 18:00
  • Thanks eryksun, I used /k and that worked. In another thread I asked why I had to change -i 1 to -i 2 because psexec suddenly stopped working with -i 1 option. But could not get any answer in the forum. If you can explain it will be helpful. Commented Feb 5, 2015 at 5:41
  • To handle simultaneous users the kernel component of the Windows subsystem (win32k.sys) is mapped to a session address space, and the namespace for named kernel objects (e.g. ALPC Port, WindowStation, Event, Mutant, Section) is partially localized to the \Sessions object directory (check accesschk -qso \Sessions). Prior to Vista (NT 6) the console shared session 0 with system services, but NT 6 isolates session 0 to system services. The "-i" option should default to the console session. Try psexec \\135.20.230.160 -s cmd.exe to open a shell to inspect available sessions. Commented Feb 5, 2015 at 8:23
  • Thanks eryksun, I will check that Commented Feb 5, 2015 at 8:44

1 Answer 1

1

Python 2

execfile("./filename") 

Python 3

exec(open("./filename").read())

There are probably also several ways to execute code and specific commands, using Python 2 commands or better for both subprocess which replaced it. Off the top of my head there are [commands|subprocess].getoutput, subprocess.Popen, subprocess.call, etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.