Jump to content

Spawning Interactive Shell with AutoIT [over psexec?]


Recommended Posts

I am trying to spawn a cmd.exe shell on a remote machine using psexec then proceed to running commands on that machine and reading the output. I.e. running pwd. 

Unfortunately, the code I have now will just immediately exit cmd on the remote system 

I'm trying to use the current code

#include <Constants.au3>
$pid = Run('C:\Users\test\Desktop\psexec.exe \\192.168.1.123 -u test -p "P@$$word1" -h -s cmd',@SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($pid,"pwd")
StdinWrite($pid,@CRLF)
Local $data
Sleep(2000)
$data &= StdoutRead($pid)
ConsoleWrite("Debug:" & $data & @LF)
StdinWrite($pid,"cd ")
StdinWrite($pid,"C:\users\test2")
StdinWrite($pid,@CRLF)
StdinWrite($pid)
$data &= StdoutRead($pid)
ConsoleWrite("Debug:" & $data & @LF)

http://stackoverflow.com/questions/19206834/command-prompt-and-autoit-stdinwrite <- credits to this stack overflow post

Unfortunately, on my end, my cmd just starts/stops with this prompt
 

Connecting with PsExec service on 192.1.123...Starting cmd on 192.168.1.123...
cmd exited on 192.168.1.123 with error code 0.

Any ideas how I can keep my shell open over psexec and still interact with it using AutoIT?

Any feed back would be amazing! Thanks!

Link to comment
Share on other sites

You probably can't, you'd need to run the commands on the target machine directly and not remotely.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 3 weeks later...

Can't you use a batch file to trigger all the commands using psexec instead of keeping it open on remote machine and sending one by one.

If you want to track the execution, you can create a log file there and copy to your machine at the end.

Link to comment
Share on other sites

  • 4 months later...
On 8/17/2016 at 9:39 AM, ur said:

Can't you use a batch file to trigger all the commands using psexec instead of keeping it open on remote machine and sending one by one.

If you want to track the execution, you can create a log file there and copy to your machine at the end.

No.  The issue that is being described is one that has been experienced by many others:

https://forum.sysinternals.com/psexec-always-hangs-when-run-from-java_topic5013.html

However, PAexec, a command line application that is essentially a clone of psexec, might give you more luck.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...