Add Tap to Continue in a bat File
I am trying to write a script and am having a hard time trying to figure something out which should be simple. I need to call an executable with a number of flags set. The problem is that after I call the executable it asks for a password (which is blank) and requires you to press enter. What I need to be able to do is send the enter key. As an example I have:
spjm -s IP -user admin -quiet -t
It then asks me for the password and I need to hit enter. Any help appreciated!
Thanks
You can try:
Batchfile
echo.|spjm -s IP -user admin -quiet -t
thumb_up thumb_down
You can do this using SendKeys ...http://msdn.microsoft.com/en-us/library/8c6yea83.aspx
Or you can use AutoIT to accomplish what you need. https://www.autoitscript.com/site/autoit/
thumb_up thumb_down
Chr(13)
thumb_up thumb_down
I've tried using both sendkeys and autoit. The code I had using sendkeys is as follows:
Text
Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "C:\Windows\System32\cmd.exe" WshShell.AppActivate "C:\Windows\System32\cmd.exe" WshShell.SendKeys"spjm -s "IP" -user admin -quiet -t" WshShell.SendKeys "{ENTER}"
I'm sure that's probably wrong. In autoit I've tried using the send("{ENTER}") method nothing seems to work.
thumb_up thumb_down
WshShell.SendKeys "~"
thumb_up thumb_down
WshShell.SendKeys "~"
That is vbscript though, not batch. I suppose you could write the batch to call the vbscript to send the enter key. That could work.
thumb_up thumb_down
WshShell.SendKeys "~"
Also, I believe it's this:
WshShell.SendKeys("{Enter}")
That's what I used on my vbscript.
thumb_up thumb_down
Here's what I tried with vbscript:
Text
Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "Path" -s "IP" -user admin -t "Path" -nc 1 -prt Printer -f "Path" WshShell.SendKeys "{ENTER}"
The script works, but I still get prompted to enter a password and press enter. I don't understand because I made the script so that it calls cmd and hits enter a bunch of times and that works fine but whenever that executable is called it doesn't seem to care. I guess I should have also mentioned that it doesn't need to be a batch file either that's just was I was trying to do.
thumb_up thumb_down
Stuffing the keyboard buffer can be tricky if the executable flushes the keyboard buffer before waiting for a key. Then, no matter what you put in the buffer, it empties it and then asks for confirmation.
You can test this by running the program and trying to type-ahead your response. If you hit enter really fast does it accept the keystroke or still wait?
thumb_up thumb_down
Couldn't I also test this by putting the enter command in twice?
thumb_up thumb_down
The way a classic keyboard flush works is that is reads characters until it is told there are no more. If you put in 2 or 10 Enters, it will pull them all out and then move on.
Here's a link to someone who stuffed the buffer with a delay that was long enough to get past the flush. Don't know if it will give you any ideas.
http://www.autohotkey.com/board/topic/87082-keyboard-stuffer/
thumb_up thumb_down
what about a sleep command then?
thumb_up thumb_down
You need a delay command.
WScript.Sleep 3000
That's the command. The number is milliseconds. That should fix the issue. Basically, right now, it's hitting enter before the prompt comes up. I would use 5000, or 5 seconds.
thumb_up thumb_down
I'd have to try this to be sure, but you could have your batch file spawn off another batch file that had a delay, then stuffed the buffer. Meanwhile, your original program could continue to launch the executable. It would look like this
START [name of batch file to delay, then stuff keyboard]
spjm -s IP -user admin -quiet -t
thumb_up thumb_down
Batch script cannot send keys to external windows. Vbs can, but you're already using it. As said, timeout is needed, because vbs tries to send enter right after it starts your app. You app definitely needs some time to initialize.
thumb_up thumb_down
I got it to work. You guys were right all I needed was the sleep command. Thanks everyone for all the help!
thumb_up thumb_down
I got it to work. You guys were right all I needed was the sleep command. Thanks everyone for all the help!
Please mark Best Answer and both Helpful Posts.
thumb_up thumb_down
Marked, thanks again guys.
thumb_up thumb_down
Apparently, MS has removed the option for 'Sendkeys' from the latest versions of Windows 10 :(
thumb_up thumb_down
Thank you for this thread, it proved to be very helpful in a task I am working on to launch an application then press enter for the app to log in for some automation.
thumb_up thumb_down
Source: https://community.spiceworks.com/topic/581479-send-enter-key-in-a-batch-file
0 Response to "Add Tap to Continue in a bat File"
Postar um comentário