write a batch script to press "tab" and "Enter" key - batch-file

I need to press "TAB" and "Enter" key using either a batch script or VB script.
OK, I'm writing the vb file in notepad. I run it by double clicking icon testVB.vbs in C:.
This is what I have:
testVB.vbs
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "test.bat"
WScript.Sleep 1000
WshShell.SendKeys (TAB) //to tab from the cancel button to open button
WScript.Sleep 1000
WshShell.SendKeys "~" //clicks open button
test.bat
#ECHO OFF
START MSAccess "C:\path\file.mdb"
I want to open Access and the DB, but a pop up window appears which is what I'm trying to get around. After I figure that out I will need to figure out how to write code to import a .txt file to the DB.
The TAB is what is not working, I have tried {TAB}, "TAB", (TAB), and different combos. I get an error with the first one and the others have no action. The enter works though ("~").

Try this;
#if (#CodeSection == #Batch) #then
#echo off
CScript //nologo //E:JScript "%~F0"
goto :EOF
#end
WScript.Sleep (1000)
WScript.CreateObject("WScript.Shell").SendKeys("{TAB}");
WScript.Sleep (1000)
WScript.CreateObject("WScript.Shell").SendKeys("~");

Related

How to merge two batch file into one batch file?

I have two batch files as below, and I want to merge them in to one btach file? (I don't want to run them seperately want to one click to run)
First one delete and copy file, second one is opens chrome and login. These batch files working properly one by one when I clicked. But I need one batch file.
Thanks for your help..
First one is:
#echo off
del "C:\web.config"
copy "C:\\Web - New.config" "C:\web.config"
Second one one is:
#if (#CodeSection == #Batch) #then
#echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
START CHROME "http://localhost:15000/"
rem the script only works if the application in question is the active window. Set a
timer to wait for it to load!
timeout /t 2
rem use the tab key to move the cursor to the login and password inputs. Most htmls
interact nicely with the tab key being pressed to access quick links.
rem %SendKeys% "{TAB}"
rem now you can have it send the actual username/password to input box
%SendKeys% "admin"
%SendKeys% "{TAB}"
%SendKeys% "1234"
%SendKeys% "{ENTER}"
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
When you have two batchfiles, batch1.bat and batch2.bat and you want both of them to run in one batchfile, the simpliest solution is to create this batchfile:
call batch1.bat
call batch2.bat
There's absolutely no problem running a batchfile from another batchfile!

How can I leftclick on google chrome with .bat file

Okay.I want to do a little app thing, and it sounds like this:
#echo off
CLS
start https://www.youtube.com/
timeout 4
#if (#CodeSection == #Batch) #then
#echo off
CScript //nologo //E:JScript "%~F0"
rem Open the browser here
goto :EOF
#end
WScript.CreateObject("WScript.Shell").SendKeys("{K}");
>nul
It basically starts a video, when you open the file, runs in the background and presses K (my attempt to solve the problem), and then I want the video to automaticaly start.
P.S.I want to use .bat, not any other extension or program.
So:
How can I make the tab to open, and the video to automaticaly play?
You can also do like this in powershell:
#Echo Off
start /d "C:\Program Files (x86)\Google\Chrome\Application\" chrome.exe new-tab "www.youtube.com/watch?v=BISQwNjP2NE"
powershell -command "& {$wsh = New-Object -ComObject Wscript.Shell; $wsh.AppActivate("Chrome"); Start-Sleep -Seconds 5; $wsh.Sendkeys(" "); $wsh.Sendkeys("+{F10}"); $wsh.Sendkeys("{DOWN}"); $wsh.Sendkeys("{ENTER}")}"
Exit /b
Thanks #It wasn't me for classic idea.
Well, this is some kind of duplicate question here, anyway, I suggest using vbs to get this result.
Obs.: Take a time to see the link video about SendKeys/VBS
<!-- :
#echo off && mode 50,03 && title <nul && title .\%~nx0
start /d "c:\Program Files (x86)\Google\Chrome\Application\" chrome.exe -new-tab "www.youtube.com/watch?v=BISQwNjP2NE"
%__APPDIR__%wScript.exe "%~dpnx0?.wsf" && goto :EOF
--> <job> <script language = "vbscript">
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.AppActivate "chrome"
WScript.Sleep 4000
objShell.SendKeys " " ' use space (charater) to play/pause
'objShell.SendKeys ("+{F10}") left click | in your question, the
'objShell.SendKeys "{DOWN}" left click | left click is not works
'objShell.SendKeys "{ENTER}" left click | for play the video
</script></job>

How do you make a batch file that opens an exe but also "clicks" the run button in that exe?

I can get the batch file to open it, but I don't know how to get it to execute the "Run Test" button. Whats the command line for this?
Updating my answer, I think tabs are best without being able to see what your windows with the button looks like. {Tab 6} here just needs to be changed. When you open the EXE with the "Run Test" button, just hit tab until you are focused on the "Run Test" button. Count the number of times you hit tab, then change the "6" in my code to that number.
#if (#CodeSection == #Batch) #then
#echo off
set SendKeys=CScript //nologo //E:JScript "%~F0"
start notepad
timeout /t 3
%SendKeys% ("{tab 6}{enter}")
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

My Batch file Is not looping?

I am new to this and I am trying a basic example I saw on Youtube:
#echo off
echo this little program helps you to refresh a website
pause
cls
echo but first we have to do some preferences
pause
cls
echo please enter the website name here
set /p website=
cls
echo please enter the time between refreshes
set /p time=
cls
echo Set limited or unlimited refresh
set /p refresh=
if'%refresh%'=='1' goto :once
if'%refresh%'=='0' goto :unlimited
cls
:once
cls
echo Preferences finished
pause
timeout /t %time% /nobreak
start %website%
exit
:unlimited
cls
echo Preferences finished
pause
:again
timeout /t %time% /nobreak
start %website%
goto :again
This code is supposed to ask a user for a website and a refresh time and it will refresh that website by reopening it in IE (Internet Explorer), however I have 2 problems with this:
The loop does not work if I enter 0 or '0' it will only execute once and exit the .bat
Is there a way to refresh a page without reopening the page in a new tab, for example just refresh the current tab ?
There are some syntax errors in your script.
EXIT command
EXIT exits the script. You may want to change that to something else.
IF Statement
if'%refresh%'=='1' goto :once
is slightly incorrect, as there is a missing space between if and the comparee. In addition, using double quotes ensure it to successfully compare with values including spaces.
if "%refresh%"=="1" goto :once
Undefined Input
If variable %refresh% is not 1 or 0, it goes to :once and execute the code there.
Refreshing Webpage
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate("Chrome")
WshShell.SendKeys "{F5}"
Save this script as Refresh.vbs and put it in the same folder as the batch file.
Then, when you want to refresh the webpage, do cscript //nologo Refresh.vbs.

Batch file for changing cmd directory and pre-filling a command

I've searched long and hard to get details on this, with no luck.
All I want to do is:
open CMD
change my working directory
enter a text string command, and pause there so I can manually enter the last portion of the command and press enter
Example:
#ECHO OFF
start cmd.exe /K "cd C:\ProgramData\Microsoft\Windows\Start Menu"
I have the first half of it working fine, it opens cmd and changes the directory - but how do I fill in the text string into the window at this point?
Ok, you want to:
open CMD
change my working directory
enter a text string command, and pause there so I can manually enter the last portion of the command and press enter
And then? After that there are two cmd.exe sessions active, so it will be problems with the following input. The Batch file below allows you do to what you want, but have the problem of what to do next. Try it and give feedback, so we can fix the details.
#if (#CodeSection == #Batch) #then
#echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
rem Start cmd.exe program
start "" cmd
rem Send whatever you want to previous cmd.exe
%SendKeys% "echo Hello world!{ENTER}"
%SendKeys% "cd C:\ProgramData\Microsoft\Windows\Start Menu{ENTER}"
%SendKeys% "echo You continue at this point: "
set /P "="
ECHO TERMINATE ORIGINAL BATCH
goto :EOF
#end
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
Try this:
#ECHO OFF
set /p "txt=Enter Path"
start cmd.exe /K "cd /d %txt%"

Resources