Jump to content
parrishjason

Spawning Interactive Shell with AutoIT [over psexec?]

Recommended Posts

parrishjason

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!

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
ur

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.

Share this post


Link to post
Share on other sites
MattHiggs
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.

Share this post


Link to post
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

  • Similar Content

    • bmy007ro
      By bmy007ro
      I have this psexec command working fine 
      Local $sMachine = InputBox("Input PC name", "Enter Computer Name")
      psexec \\$sMachine -u $sDomain\$sUserName -p $sPassword  \\NetworkFLD\FILENAME.cmd > C:\Temp\TT\My.log
       
      I wanted to converted to AutoIT script
      Cloud you help, please !?
       
    • VITSUSA
      By VITSUSA
      I am using window XP in my desktop, so I want to convert basic disk to a dynamic disk, so how it is possible?
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      With this script you can print Unicode text in the CMD screen
      the script is  easy to use
      just you  write the text that contains Unicode in the first input
      and the script automatically reflect the code in the second input
       you can copy the text to the clipboard
      or you can try printing the text in the CMD window
      I apologize to everyone for colors and shape if not appropriate
      I'm a blind man and I do not see
      Thank you for your understanding
      Greetings to all of youCmdUtM.au3
    • ur
      By ur
      I have an aws cloud machine where I kept all the build process to create some set of zip files and uploading them to OneDrive.
      Once it is completed, I have another local machine in our environment which is a acting as a local share server also.
      Is there anyway to notify this machine(without public IP) to start downloading these files.
      I have written an AutoIT exe to download these files and copy them to respective locations.But don't know how to notify this from the remote machine.
       
      Any suggestion??
       
    • Piotr_Hodl
      By Piotr_Hodl
      Hi guys,
       
      My post is more architecture related than the actual autoit script.
      Currently I have a java tool that makes a connection to a azure Windows VM using WINRM.
      Then I "grep" the session ID of RDP and using psexec I execute my autoit script on the session ID of the RDP (This assumes that I need to have already a RDP connection established).
      The script runs perfectly when I have a RDP session maximized/opened. If I minimize the RDP window some commands do not work, as for example the Send command.
      I do understand that it has to do with the window not being active, even though the script is executed remotely.
      https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F
       
      My goal is to be able to run the autoit scripts with no limitations, like I was running in my local machine.
       
      One important thing, all the flow is being triggered from a linux machine with no GUI. So that is why, I am using a jar file to start the winrm connection.
       
      So to sum up:
      starting server: centos with no GUI
      remote server: azure win 10
      goal: from starting server, launch autoit script that is on remote server
       
      Thanks
      Piotr
       
       
       
×