vbscript opens mp4 in wmplayer, but only audio plays - batch-file

I'm trying to simply open a video in full screen using a batch file, I realised this wasn't possible so I included code to make it write to vbscript instead and then later on execute the vbscript code.
I'm running windows 10, and I have another script running an mp3 file that works fine.
This is what my batch file is writing to the vbscript
set "file2=res\FORTNITESKINS.mp4"
( echo Set wmp = CreateObject("WMPlayer.OCX"^)
echo Video.URL = "%file2%"
echo Video.Controls.play
echo do while Video.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Video.currentmedia.duration^)+1^)*1000
echo set WshShell = WScript.CreateObject("WScript.Shell"^)
echo WScript.Sleep 1000
echo WshShell.SendKeys "%{ENTER}") >video.vbs
This is how I execute the vbscript
start video.vbs
The video does not open, only the audio plays, and wmplayer doesn't even open minimized, nor can I find it in task manager.
I have also tried this,
set "file2=res\FORTNITESKINS.mp4"
( echo Set Video = CreateObject("WMPlayer.OCX"^)
echo Video.openPlayer("%file2%"^)
echo set WshShell = WScript.CreateObject("WScript.Shell"^)
echo WScript.Sleep 1000
echo WshShell.SendKeys "%{ENTER}") >video.vbs
but it gives the error:
Line: 2
Char: 1
Error: 0xC00D1329
Code: C00D1329
Source: (null)

Why don't you use wmplayer directly with proper command-line-parameters ?
#Echo off
set "file2=res\FORTNITESKINS.mp4"
set wmplayer="%ProgramFiles(x86)%\Windows Media Player\wmplayer.exe" /prefetch:1
%wmplayer% "%file2%" /fullscreen

You can do it like this example :
#echo off
Mode 70,3 & color 0B
echo(
Set "Title=Playing videos with Windows Media Player"
Title %Title%
echo %Title%
Set "URL-FILE=http://1290922571.rsc.cdn77.org/movies/Superman-Unbound-2013-FRENCH.mp4/playlist.m3u8"
Start "%Title%" wmplayer /fullscreen "%URL-FILE%"
Timeout /T 2 /NoBreak>nul
EDIT :
#echo off
Mode 70,3 & color 0B
echo(
Set "Title=Playing videos with Windows Media Player"
Title %Title%
echo %Title%
Set vbs_video=%temp%\vbs_video.vbs
Set video=http://1290922571.rsc.cdn77.org/movies/Superman-Unbound-2013-FRENCH.mp4/playlist.m3u8
Call :Play %video%
Timeout /T 2 /NoBreak>nul & Exit
REM ***************************************
:Play <video>
(
echo Set Video = CreateObject("WMPlayer.OCX"^)
echo Video.openPlayer("%~1"^)
echo set WshShell = CreateObject("WScript.Shell"^)
echo WScript.Sleep 3000
echo WshShell.SendKeys "%%{ENTER}"
)>"%vbs_video%"
Start "video" "%vbs_video%"
exit /b
REM ***************************************

set "file2=F:\ull\path\to\res\FORTNITESKINS.mp4"
You must enter the full path to the file for the script to work. Including the drive letter and the path to the current folder.

Related

Play a song 3 times using a batch file on VLC

I'm a beginner in this script, even though I know some basic vanilla JS. I want to make a batch file that could run 3 times...
Here is what I have tried, batch file just runs and closes. I'm not sure why this happens? Can I make it work?
#echo off
for /l %%v in (1,1,3) do (
set "file=AKАТИСТ светом Архангелу МИХАИЛУ - AKATIST.mp3"
( echo Set Sound = CreateObject("VLCplayer.xspf"^)
echo Sound.URL = "D:\AKАТИСТ светом Архангелу МИХАИЛУ - AKATIST.mp3"
echo Sound.settings.volume = 76
echo Sound.Controls.play
echo While Sound.playState ^<^> 1
echo Wend
run Sound
)
)

Creating music with batch

i wanted to know if there is some way of doing music with batch, not just opening a mp3 file from cmd, but commands to do notes or something like that. If there really isn't how to do it, i understand.
batch can play music by creating and starting a vbs script to Leverage the internal windows media player.
Note: In all the below scripts, the variable %sounds% refers to the folder your sound scripts are located, and must be defined.
The core of playing music is the following Batch Script:
#Echo off & REM MusicPlayer.bat
Set "MusicPath=%~1" & REM Full Path for the music file
Set "vol=%~2" & REM Volume as number between 0 and 100
Set "LoopTF=%~3" & REM 'paramater 3 as 'true' or 'false' determines if the track is to be looped.
(
PUSHD %sounds%
%= Change to the directory your sound files are located =%)
::: Ensure no Conflict with the Previous Script.
IF exist PlayMusic.vbs (
DEL PlayMusic.vbs
)
::: Creates a vbs Script to launch the music (Occurs without any visual indication or prompting)
(
echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
echo Sound.URL = "%MusicPath%"
echo Sound.settings.volume = %vol%
echo Sound.settings.setMode "loop", %LoopTF%
echo Sound.Controls.play
echo While Sound.playState ^<^> 1
echo WScript.Sleep 100
echo Wend
echo Sound objTS = Nothing 'Destroy the object.
)>PlayMusic.vbs
start /min PlayMusic.vbs
(
POPD
%= Return to your Previous Directory =%)
::: Exit the Launcher and return to Previous batch program.
GOTO :EOF
The above script is called with 3 parameters as Remarked.
Another Vbs can be used to Monitor the batch's status and call a batch script to stop the music when the batch is closed:
#Echo off & REM Monitor.bat
(
ECHO Set objWMIService = GetObject ("winmgmts:"^)
ECHO Set proc = objWMIService.ExecQuery("select * from Win32_Process Where Name='cmd.exe'"^)
ECHO DO while proc.count ^> 0
ECHO Set proc = objWMIService.ExecQuery("select * from Win32_Process Where Name='cmd.exe'"^)
ECHO if proc.count ^< 1 then exit do
ECHO wscript.sleep 1500
ECHO loop
ECHO Set WshShell=createobject("wscript.shell"^)
ECHO WshShell.run "%sounds%\KillMusic.bat", 0, true
)>%sounds%\MusicMonitor.vbs
start %sounds%\MusicMonitor.vbs
Goto :EOF
The above script creates a hidden vbs that fetches the number of instances of cmd.exe via the objWMIService.ExecQuery. This occurs during a loop, with the break condition being 0 open cmd.exe windows. A sleep is built into the loop to reduce the frequency of calls to the WMI service, as these are very resource intensive. When the loop break occurs, it starts the killmusic.bat program in a hidden state.
The below script "KillMusic.bat" is called either directly in your quit label or by the vbs monitor when it determines Cmd.exe is no longer running. DoMonitor is a variable that is changed in your main script prior to killmusic being called. 1 indicates the monitor should be restarted, and is used when killmusic.bat stops a currently playing song to start a new song. Monitor is a Variable containing the path to Monitor.bat
#ECHO OFF & REM KillMusic.bat
taskkill /pid WScript.exe /f /t >nul
IF exist "%sounds%\PlayMusic.vbs" (
DEL /Q "%sounds%\PlayMusic.vbs"
)
Timeout 1 > nul
IF "%DoMonitor%"=="1" GOTO reset
GOTO :EOF
:reset
CALL "%Monitor%"
GOTO :EOF
These three programs can be seen in effect here.

Execute specific vbs file from batch file

Batch content:
echo Set wshShell =wscript.CreateObject("WScript.Shell")>"C:\Users\Riccardo\Desktop\prova.vbs"
<nul set /p =wshshell.sendkeys ^"^<nul set ^/p ^=>>"C:\Users\Riccardo\Desktop\prova.vbs"
Type "C:\Users\Riccardo\Desktop\prova.txt">>"C:\Users\Riccardo\Desktop\prova.vbs"
echo {bs}^>^"^"C:\Users\Riccardo\Desktop\prova.txt^"^"{enter}^">>"C:\Users\Riccardo\Desktop\prova.vbs"
wscript "C:\Users\Riccardo\Desktop\prova.vbs"
The vbs generated is:
Set wshShell =wscript.CreateObject("WScript.Shell")
wshshell.sendkeys "<nul set /p =La#{bs}>""C:\Users\Riccardo\Desktop\prova.txt""{enter}"
The prova.txt contains:
La#
After execute this line from new command prompt session:
wscript "C:\Users\Riccardo\Desktop\prova.vbs"
The prova.txt becomes
La
But if execute the same line as above from batch:
wscript "C:\Users\Riccardo\Desktop\prova.vbs"
nothing happens!
How can I fix the problem?
Try to call the script like so:
C:\Users\Riccardo\Desktop\prova.vbs
If that doesn't work, change directory to your desktop, and call the vbs:
cd C:\Users\Riccardo\Desktop\
prova.vbs
That should work in a batch file.
I am solved the my problem. The "Prova.bat" code is:
echo Set wshShell =wscript.CreateObject("WScript.Shell")>prova.vbs
echo wshShell.Run "cmd">>prova.vbs
echo WScript.Sleep 250>>prova.vbs
<nul set /p =wshShell.sendkeys ^"^<nul set ^/p ^=>>prova.vbs
Type prova.txt>>prova.vbs
<nul set /p ={bs}^>prova.txt{enter}exit{enter}^">>prova.vbs
wscript prova.vbs
DEL /q prova.vbs 2> NUL
The "Prova.vbs" generated and deleted is:
Set wshShell =wscript.CreateObject("WScript.Shell")
wshShell.Run "cmd"
WScript.Sleep 250
wshShell.sendkeys "<nul set /p =La#8{bs}>prova.txt{enter}exit{enter}"
The "Prova.txt" before:
La#8
The "Prova.txt" now:
La#
I am found the way of insert backspace character in a txt file using bat+vbs file! ;-) I hope that such a solution can be of help to someone else.

Batch Get User Input To Put Into A File

I have this code:
loop
echo -- File Created With LuaIDE. Do NOT Remove This Line > LuaCode.lua
set /p Lua=Lua:
%Lua% >> LuaCode.lua
if %Lua% == "LuaIDE.Exit()" ( echo Thanks for using LuaIDE!
timeout /t 3 /nobreak >nul
exit )
goto loop
and what i want it to do is get User-Input and put it into a file and if the user input is "LuaIDE.Exit()" I would like it to say a message for 3 seconds and exit but it just says:
'whatever you type in' is not recognized as an internal or external command,
operable program or batch file.
Why does it do this?
You have a few bugs. Try this:
echo -- File Created With LuaIDE. Do NOT Remove This Line > LuaCode.lua
:loop
set /p Lua=Lua:
echo %Lua% >> LuaCode.lua
if %Lua%==LuaIDE.Exit() goto exit
goto loop
:exit
echo Thanks for using LuaIDE!
ping 1.1.1.1 -n 3 -w 1 >nul
exit
Try this:
#echo off
:loop
echo -- File Created With LuaIDE. Do NOT Remove This Line > LuaCode.lua
set /p Lua=Lua:
echo %Lua%>>LuaCode.lua
if /i "%Lua%" == "LuaIDE.Exit()" echo Thanks for using LuaIDE & timeout /t 3 /nobreak >nul & exit
goto loop
Let me know how it works.
stop complicating a simple task....
the code is as simple as
#echo off
: start
echo.
set /p input= type your text here:
echo %input%>>myfile.extension
timeout /t 5 >null
cls
goto start
replace myfile with name of your file you want to send text.
replace extension with any that you want txt,log , etc
also you can specify path of your file e,g
echo %input%>>path/directory

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