How can I open a file in Batch without focusing on it? - batch-file

I'm using the start command to open a .mp3 or .wav file in wmplayer along with other certain events in a Batch program I'm writing. It works perfectly, and is accompanied by TASKKILL /IM wmplayer.exe to stop the program when the user goes to the next screen of the application. The only thing that could make it work more smoothly is if the program would open in the background, so the user doesn't have to click back into CMD. Is there any way to open the sound effect in wmplayer without switching focus over to wmplayer, and furthermore remaining selected into CMD? Thanks in advance.

You could have the original batch file open an alternate one after opening your wmplayer.exe to put the alternate on top. From there you could program the alternate to do all the same things your original file would do.
For example your main file's code could be:
#echo off
title Yourtitle
start wmplayer.exe
start AltBatch.bat
exit
And your alternate (AltBatch.bat):
#echo off
title YourTitle
:: (Your code here)
Or, simply put this would be the layered order on screen:
Original > wmplayer.exe > Alternate

So let me know if this code can did the trick or not ?
You just change the path of your sound !
#echo off
Title Playing sound on the background while executing some commands
set Soundfile=http://hackoo.alwaysdata.net/feeling.mp3
( echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
echo Sound.URL = "%Soundfile%"
echo Sound.Controls.play
echo do while Sound.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /min sound.vbs
ping www.google.com
ping www.stackoverflow.com
tracert www.google.com
tracert www.stackoverflow.com
pause

Related

Why Are All My Programs Opening When I Call One Function That's Supposed To Start One Program?

I'm tryng to write a batch file which starts programs, but two problems arise:
If I use one command, it opens the others (i.e. If I open the calculator, it also opens the curler
Here is the code for my program:
#echo off
cls
title Console
:prompt
set /p prompt=:
goto %prompt%
:help
echo Commands
echo ---------------
echo help........................Shows this list
echo calc........................Starts the CMD Calculator
echo retaskbar...................Starts the Taskbar Fixer
echo curler......................Starts the Curler
echo webping.....................Starts Website Pinger
echo.
pause
goto prompt
:calc
start calc.exe
:retaskbar
start retaskbar.exe
:curler
start curler.exe
:webping
start webping.exe
I'm planning to turn this into a single exe file for more convenience.

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.

how to detect change in .txt file using batch?

I made a simple LAN chat batch file, and i would like to know if
there is an command that checks if a specific txt file is updated.
The chat history is stored in log.dat and i want to have a sound notification or something like that when theres a new message.
#echo off
title LAN chat reader
call Color.bat
:read
call Color.bat
cls
type log.dat
timeout /t 3 /nobreak >nul
goto read
(im a noob, please tell me if this is possible)
To check the file date/time use for and %%~t prefix:
#echo off
title LAN chat reader
setlocal enableDelayedExpansion
:read
call Color.bat
cls
type log.dat
for %%a in (log.dat) do set filetimesize=%%~tza
:checkupdate
ping -n 1 -w 100 localhost >nul
for %%a in (log.dat) do if "!filetimesize!"=="%%~tza" goto checkupdate
echo updated
goto read
wOxxOm already gave a solution to check for an updated file.
Here is a way to produce a Sound:
copy con bell.txt
Then press the ALT-key enter 007 while keeping ALT pressed, then release the ALT key. ^G should appear on your Screen (= 0x07, which is a Bell), then press Ctrl-Z. This gives you a textfile with lenght = 1 Byte
Type bell.txt
will then beep.
EDIT an easier way to produce bell.txt: on commandline, enter echo ^G>bell.txt (to produce ^G press CTRL-G). This will create a three-byte-file (instead of the one-byte-file with the copy trick) (but that's only a line feed and should not disturb).

Problems in my simple chat program

I made a simple batch chat that write the message to an txt file.
I need help with print the file every time it changed and with hidding output.
I used the type, delay and cls to print the file but it didnt work, it didnt printed the file.
launcher.bat:
start cmd /k
call room.bat
call chat.bat
using the launcher photo
room.bat(the problem):
:chat1
cls
TYPE room.txt
timeout /t 0.5
goto chat1
chat.bat(working but show extra info about the os and the file):
#echo off
cls
set D=%Date%
cls
echo enter your name
SET /P name=[name]
pause
:room
cls
SET /P chatpublic=[everyone]
SET "
echo %name%: %chatpublic% |%D%|>> room.txt
pause
goto room
without the launcher photo
Here's the culprit:
echo %name%: %chatpublic% |%D%|>> room.txt
That's because the | vertical line has a special meaning in Windows command line interpreter: commandA | commandB: pipe the output from commandA into commandB.
If you do want use a | vertical line in another sense (e.g. display it with an echo command), then you should escape it as follows:
echo %name%: %chatpublic% ^|%D%^|>> room.txt

Cursor in middle of text in batch

I am looking for a way to place the cursor between several lines of echo commands so it appears that the pause is in the center of the code, rather than at the end, while still displaying the last line of text and not continuing to the next label until hitting anykey. is this possible?
I want to have the appearance that the last line of actual text is a footer, seperat from the above text.
At the moment, my sequencing looks similar to this:
:LABEL
CLS
ECHO text1
ECHO.
ECHO.
(want the PAUSE to appear here)
ECHO.
ECHO.
ECHO text2
PAUSE (while the PAUSE is really here to prevent text2 from being lost)
GOTO OTHERLABEL
Thanks a bunch!
I think I know what you are asking, correct me if I am wrong. You want this functionality:
echo hello
pause
echo bye
But you want to switch the location on the screen of the pause and echo bye. If so, that is not easy. I suppose you could use a vbscript that once the first pause runs in the above code, would send a key to the batch file, which would echo. a ton of times and then pause again, and then the vbscript could scroll up in the batch file. It's not worth it.

Resources