How can I leftclick on google chrome with .bat file - batch-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>

Related

How do i get a batch script to show real time progress bar, while waiting for another script to finish?

Hi im not really good in writing batch scripts, im new to this, i really need help,
The script i have needs to do an unattended installation,
i got that part to work, what i need is to show a progress bar for the users to see the progress of the installation,
the script i have is below:
#echo off
echo --------------------------------------------------------------
echo --------------------------------------------------------------
echo Software is installing......
echo.
echo please wait, do not close!!
echo.
C:\files\gw18\win32\install.bat /unattended
cls
i found this really cool progress bar script, i need help to make it work with the above
#echo off
setlocal EnableDelayedExpansion
set Counter=0
set Schalter=2
set Width=0
:1
title Animation Box - Installation
set /a Counter=%Counter% + 1
set /a Display=%Counter% / 2
FOR /L %%A IN (1,1,%Display%) DO (
set Display=!Display!²
)
cls
echo Progress... %Counter%%%
echo ²!Display:~2,47!
ping localhost -n 1 >nul
if "%Counter%" == "100" goto :1-End
goto :1
:1-End
echo.
echo Installation complete.
pause >nul
Or any progress bar code that will work
Thank you in advance :)
What I would recommend doing for the progress bar script, is make it so that the installer outputs a text file every time it completes a task. For example, when it completes MOVE file.exe "C:\Program Files\Application", echo EXE Move Completed. > 1.txt.
Then, the progress bar script would constantly watch for those files, then update the progress bar accordingly. Example:
:watch1
if exist 1.txt goto update1
goto watch1
:update1
cls
echo Progress: 0========== 0
DEL 1.txt
goto watch2
:watch2
if exist 2.txt goto update2
goto watch2
And so on.
So every time the progress bar script finds a new file outputted by the installer, it adds a little bit more to the progress bar.
Hope this helped.

Start Firefox from a batch file

I am trying to create a batch file which starts Firefox, and prints "Firefox started" on the screen. I had to use the "start" command so that my batch file doesn't stop running after Firefox is started.
#start "C:\Program Files\Mozilla Firefox\firefox.exe"
#echo Firefox started.
#pause
Instead a command line of Firefox is started. Can someone help me?
Thanks
This should do:
#echo off
start "" "C:\Program Files\Mozilla Firefox\firefox.exe"
echo Firefox have started.
...Do something else here...
pause
If you want to be a little fancier, echo to a cscript which will popup a windows, where you have to click Ok, before the batch file will continue to the next command.
#echo off
echo Set objArgs = WScript.Arguments > DisplayMsg.vbs
echo messageText = objArgs(0) >> DisplayMsg.vbs
echo MsgBox messageText >> DisplayMsg.vbs
start "" "C:\Program Files\Mozilla Firefox\firefox.exe"
timeout /t 3
cscript DisplayMsg.vbs "Firefox has Started successfully!"
...Do something else here...
pause
for more on the actual starting of firefox, do start /? from commandline for help. You have however used # before your commands, which actually turns echo off.
#ECHO OFF
SETLOCAL
start "Firefox!" "C:\Program Files\Mozilla Firefox\firefox.exe"
echo Firefox started.
pause
GOTO :EOF
The first quoted argument in a start becomes the window title. Insert a dummy quoted argument (the content is irrelevant) and all should be well.
Using an #echo off statement means that the # doesn't need to be used in following lines. The # says "don't echo this command". #echo off means "turn off echoing" (which can be turned on again by echo on) - the # in #echo off means "don't echo the ECHO OFF statement"

Launch a Java/Batch hybrid without displaying command prompt

A little while I asked a question (and got a brilliant response) to create the program below, what I'd like to is silently launch it, so the command prompt does not display in the background.
The program below tests for "Agent.exe" and if it finds it, displays a message box to the user telling them the program will close in 2 minutes unless they press ok.
now
I came across this VBS script
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "Program goes here" & Chr(34), 0
Set WshShell = Nothing
but have not the tiniest clue to combine it with my script
#if (#CodeSection == #Batch) #then
setlocal
for /f %%I in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "beep=%%I"
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
setlocal
set "task=agent.exe"
set "timeout=120"
rem // Is %task% running?
tasklist /fi "imagename eq %task%" | find /i "%task%" >NUL && (
rem // Re-launch script with JScript interpreter
wscript /e:JScript /nologo "%~f0" %timeout% || (
rem // If timeout or user hits No, kill %task%
taskkill /im "%task%" /f
)
)
rem // End main runtime
goto :EOF
rem // Begin JScript portion
#end
var osh = WSH.CreateObject('WScript.Shell'),
nag = 'Greetings! Your administrator has requested you to log out of Program '
+ 'after work. It appears you are still using it.'
+ ' If you are still here, Press Yes to continue working.\n\n'
+ 'Otherwise, press no to close Program.'
+ 'Program will close automatically in less than ' + WSH.Arguments(0) + ' seconds.';
popup = osh.Popup(nag, WSH.Arguments(0), 'Are you still here?', 0x4 + 0x20 + 0x1000);
WSH.Quit(popup - 6);
Anyone have any ideas?
(shoutout to Rojo, who answered my initial Question with the above script)
To answer your question, that VBScript snippet will work. Just save it with a .vbs extension and replace "Program goes here" with the path + filename of your batch script. When you double-click the vbs file or execute it with wscript /nologo "path\to\vbsfile", it will run the batch script hidden (no console window) but the popup will still appear.
If you'd prefer to keep all your code within a single file, you could invoke powershell -windowstyle hidden to hide the window. You'll still see the black window for a second, but it'll disappear before the popup appears.
#if (#CodeSection == #Batch) #then
setlocal
rem // hide current window
powershell -windowstyle hidden -command ""
for /f %%I in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "beep=%%I"
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
set "task=agent.exe"
set "timeout=120"
rem // Is %task% running?
tasklist /fi "imagename eq %task%" | find /i "%task%" >NUL && (
rem // Re-launch script with JScript interpreter
wscript /e:JScript /nologo "%~f0" %timeout% || (
rem // If timeout or user hits No, kill %task%
taskkill /im "%task%" /f
)
)
rem // if not in a self-destructing window, re-show
set "caller=%cmdcmdline:"=%"
if /I not "%caller:~0,6%"=="cmd /c" powershell -windowstyle normal -command ""
rem // End main runtime
goto :EOF
rem // Begin JScript portion
#end
var osh = WSH.CreateObject('WScript.Shell'),
nag = 'Greetings! Your administrator has requested you to log out of the Cisco '
+ 'Agent Desktop after work. It appears you are still using it. If you '
+ 'are still here, Press Yes to continue working.\n\n'
+ 'Otherwise, press No to close the agent. Agent will close automatically '
+ 'in less than ' + WSH.Arguments(0) + ' seconds.',
popup = osh.Popup(nag, WSH.Arguments(0), 'Are you still here?', 0x4 + 0x20 + 0x1000);
WSH.Quit(popup - 6);
Shout received and appreciated. I still think you ought to play a cheesy midi file instead of beeping. :)

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%"

How to create batch file which opens an website e.g. gmail.com and enters user name and password

i need to create a batch file which opens a website(gmail) and enters username and password.
so can anyone help me please..
Thank you.
here is the code i tried.. It opens gmail, now how can i enter username and password.
saved as Test.bat
#echo off
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE https://gmail.com
Won't let me comment, but I agree the batch is the wrong way to do this. You could do this with PowerShell though.
add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
#Loads Website
C:\Progra~1\Intern~1\iexplore.exe -k http://www.gmail.com
#Enter Credentials
[System.Windows.Forms.SendKeys]::SendWait("userid{TAB}password{enter}")
You cannot do this. You can open a specific url, but you cannot enter values in a form.
You can open an e-mail adress from the command prompt, but that will open the default e-mail client, and not some webmail page. So unfortunately, it's not possible.
I don't think there's a purely-batch way of achieving your goal.
You may try to write something up, using, for example, http://jsoup.org/ . But you'll need to change your code every time there's a new specification on the page.
This can be done with Selenium. You need to write a simple Selenium JUnit test in Java. Of course, this requires that Java be installed on the computer. It would be about 20-30 lines of code. Then, you can execute the JUnit test from a batch file like so:
#ECHO off
SET username=me
SET password=mypassword
java -cp MyGmailTest.class MyGmailTest %username% %password%
timeout 10
Use selenium's firefox WebDriver with java.
http://docs.seleniumhq.org/download/
Import all the necessary webDriver librarys, and it will very simple. Something like this:
public class checkEmail{
public static void main(String args[]){
WebDriver driver = new FirefoxDriver();
driver.get("www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("your usernamne");
driver.findElement(By.id("Passwd")).sendKeys("your password");
driver.findElement(By.id("signIn")).click();
}
}
get the .class files, then make a simple batch file
#ECHO OFF
set CLASSPATH= (wherever your selenium jars are)
cd C:\where ever the class file is
java checkEmail
WITH FIREFOX:
#echo off
set command=C:\Users\%USERNAME%\Desktop\GMAIL.VBS
start https://gmail.com
echo Set objShell = WScript.CreateObject("WScript.Shell") > %command%
echo Set WshShell = WScript.CreateObject("WScript.Shell") >> %command%
echo Do Until Success = True >> %command%
echo Success = objShell.AppActivate("Mozilla Firefox") >> %command%
echo Loop >> %command%
echo WshShell.SendKeys "USERNAME HERE" >> %command%
echo WshShell.SendKeys "{TAB}" >> %command%
echo WshShell.SendKeys "[PASSWORD HERE] >> %command%
echo WshShell.SendKeys "{ENTER}" >> %command%
ping 192.0.2.2 -n 1 -w 5000 > nul
start %command%
ping 192.0.2.2 -n 1 -w 1000 > nul
del %command%
exit
chance [USERNAME HERE] AND [PASSWORD] { with the [ ] }
WITH GOOGLE CHROME
#echo off
set command=C:\Users\%USERNAME%\Desktop\GMAIL.VBS
start https://gmail.com
echo Set objShell = WScript.CreateObject("WScript.Shell") > %command%
echo Set WshShell = WScript.CreateObject("WScript.Shell") >> %command%
echo Do Until Success = True >> %command%
echo Success = objShell.AppActivate("Google Chrome") >> %command%
echo Loop >> %command%
echo WshShell.SendKeys "USERNAME HERE" >> %command%
echo WshShell.SendKeys "{TAB}" >> %command%
echo WshShell.SendKeys "[PASSWORD HERE] >> %command%
echo WshShell.SendKeys "{ENTER}" >> %command%
ping 192.0.2.2 -n 1 -w 5000 > nul
start %command%
ping 192.0.2.2 -n 1 -w 1000 > nul
del %command%
exit
chance [USERNAME HERE] AND [PASSWORD] { with the [ ] }
#if (#CodeSection == #Batch) #then
#echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
%SendKeys% "{ENTER}"
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
While i myself am still experimenting and testing this batch file program on different applications, i am not sure as to the inner-workings of what this program actually does. All i know is it uses a java script installed on every windows computer to push keyboard commands to be executed. However in my experimentation i found that it could also serve as a means to fill in passwords and usernames.
#if (#CodeSection == #Batch) #then
#echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
START FIREFOX "WWW.EXAMPLE.COM"
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 5
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.
%SendKeys% "{TAB}"
rem now you can have it send the actual username/password to input box
%SendKeys% "username{TAB}"
%SendKeys% "password{ENTER}"
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
check this

Resources