kakarotsaiyan Posted September 13, 2018 Share Posted September 13, 2018 I'm trying to tweak an application using command prompt. Everything works fine, the script runs in the background except for "shift" key i guess because i'm using chrome while the script is running and some of the text i'm typing get capitilized and "enter" key too i think. Is there some other command to send text to CMD.exe more effectively in the background? Any help is appreciated. Thank you. Run(@ComSpec & " /k " & "cd D:\Program Files\Admin\Secureset","",@SW_HIDE) WinWait("Administrator: C:\WINDOWS\system32\cmd.exe","",10) $hCmd = WinGetHandle("Administrator: C:\WINDOWS\system32\cmd.exe") Sleep(500) ControlSend($hCmd, "", "", "{!}check connected 192.168.0.25" & "{ENTER}") .... => remaining script similar commands of controlsend. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 13, 2018 Share Posted September 13, 2018 @kakarotsaiyan StdinWrite() spudw2k 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
kakarotsaiyan Posted September 13, 2018 Author Share Posted September 13, 2018 @FrancescoDiMuro It didn't work . Is there something wrong in what i did below? as the CMD.exe didn't exit $pid = Run(@ComSpec & " /k " & "cd D:\Program Files\Admin\Secureset","",@SW_SHOW) WinWait("Administrator: C:\WINDOWS\system32\cmd.exe","",10) $hCmd = WinGetHandle("Administrator: C:\WINDOWS\system32\cmd.exe") Sleep(500) StdinWrite($pid, "exit" & "{ENTER}") Link to comment Share on other sites More sharing options...
ajag Posted September 13, 2018 Share Posted September 13, 2018 Help "StdinWrite": Remarks StdinWrite() writes to the console standard input stream for a child process, which is normally used by console applications to read input from the user i.e. from the keyboard. During the call to Run() for the child process you wish to write to the STD I/O parameter must have included the value of $STDIN_CHILD (1) for this function to work properly (see the Run() function). So update your Run() statement to #include <AutoItConstants.au3> $pid = Run(@ComSpec & " /k " & "cd D:\Program Files\Admin\Secureset","",@SW_SHOW, $STDIN_CHILD ) Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
kakarotsaiyan Posted September 13, 2018 Author Share Posted September 13, 2018 (edited) @ajag i tried but it just opened a cmd window where there was no directory, i couldn't even enter anything manually. In the below code the window just closes -as the script ended but not because of the exit command as it didn't even get entered. OK, i got it- i needed to add StdinWrite($pid, @CRLF) #include <AutoItConstants.au3> $pid = Run(@ComSpec & " /k " & "cd D:\Program Files\Admin\Secureset","",@SW_SHOW, $STDIN_CHILD) WinWait("Administrator: C:\WINDOWS\system32\cmd.exe","",10) $hCmd = WinGetHandle("Administrator: C:\WINDOWS\system32\cmd.exe") Sleep(500) StdinWrite($pid, "exit" & "{ENTER}") StdinWrite($pid, @CRLF) .THANK YOU <3 Edited September 13, 2018 by kakarotsaiyan Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now