I created an batch-script that positioned with youtube-dl and ffmpeg. I set several set to put URL and Video/Audio ID. Here my script that I simplified
#echo off
cd /d %root%\YT
color 0a
title Youtube Downloader
setlocal enableDelayedExpansion
set q=^"
color 0a
:submenu
echo Please enter URL.
set /p f1="URL: "
echo Checking ID...
youtube-dl -F %f1%
ping localhost -n 2 >nul
goto menu
:menu
echo.
echo Script created by UrbaseR
echo ___________________________________________________________
echo.
echo MENU
echo ___________________________________________________________
echo OS Windows - %ComputerName%
echo.
echo M E N U
echo Press 1 to Download Best version
echo Press 2 to Download Custom version + convert
echo Press 3 to Exit
set /p you=">"
if %you%==1 goto 1
if %you%==2 goto 2
if %you%==3 goto 3
cls
echo *********************************
echo Sorry invalid number!
echo *********************************
ping localhost -n 2 >nul
goto menu
:1
echo Downloading...
youtube-dl -f best %f1%
echo.
echo Done
ping localhost -n 2 >nul
cls
goto submenu
:2
set /p id1="Insert Video ID: "
set /p id2="Insert Audio ID: "
echo Downloading Video..
youtube-dl -f %id1% -ciw -o "vid.%(ext)s" -v --write-sub %f1%
echo.
echo Video Done
ping localhost -n 2 >nul
echo Downloading Audio..
youtube-dl -f %id2% -ciw -o "aud.%(ext)s" -v %f1%
echo.
echo Audio Done
ping localhost -n 2 >nul
echo Converting Video
ffmpeg -i "vid.%(ext)s" -i "aud.%(ext)s" -c:v copy -c:a aac -strict experimental "input.mkv"
echo Converting Done
ping localhost -n 4 >nul
cls
goto submenu
:3
exit
First and third option execute successfully. Second option will appear the message like this:
Usage: youtube-dl [OPTIONS] URL [URL...]
youtube-dl: error: You must provide at least one URL.
Type youtube-dl --help to see a list of all options.
Note: Since I stuck on first and second stage of youtube-dl, ffmpeg may not work (I have not tested it yet).
Can you help me?
After re-fix the script is pretty much done.
#echo off
cd /d %root%\YT
color 0a
title Youtube Downloader
setlocal enableDelayedExpansion
set q=^"
color 0a
:submenu
echo Please enter URL.
set /p f1="URL: "
cls
echo Checking ID...
youtube-dl -F %f1%
ping localhost -n 2 >nul
goto menu
:menu
echo.
echo.
echo Script created by UrbaseR
echo ___________________________________________________________
echo.
echo MENU
echo ___________________________________________________________
echo OS Windows - %ComputerName%
echo.
echo M E N U
echo Press 1 to Download Best version (default ver)
echo Press 2 to Download Custom version + Convert
echo Press 3 to Exit
echo.
echo URL: %f1%
set /p you=">"
if %you%==1 goto 1
if %you%==2 goto 2
if %you%==3 goto 3
cls
echo *********************************
echo Sorry invalid number!
echo *********************************
ping localhost -n 2 >nul
goto menu
:1
echo Downloading...
youtube-dl -f best %f1%
echo.
echo Done
ping localhost -n 2 >nul
cls
goto submenu
:2
set /p id1="Insert Video ID: "
set /p id2="Insert Audio ID: "
set ida="v.data"
set idb="a.data"
set "f2="
set "f3="
cls
echo Downloading Video..
youtube-dl -f %id1% -ciw --o %ida% -v --write-sub %f1%
echo.
echo Video Done
ping localhost -n 2 >nul
cls
echo Downloading Audio..
youtube-dl -f %id2% -ciw -o %idb% -v %f1%
echo.
echo Audio Done
ping localhost -n 2 >nul
cls
echo Note Default title is: input.mkv
echo.
set /p f2="Enter Video Title: "
if not defined f2 set "f2=input"
set /p f3="Format Video: "
if not defined f3 set "f3=mkv"
echo Converting Video..
ffmpeg -i %ida% -i %idb% -c:v copy -c:a aac -strict experimental "%f2%.%f3%"
echo Converting Done
del /q %ida%
del /q %idb%
ping localhost -n 4 >nul
cls
goto submenu
:3
exit
Feel free to use the script.
Note: Be sure to have youtube-dl.exe and ffmpeg.exe on same folder, video will also saved on same folder .
I'm new to this so try to keep my question relevant! I'm trying to write a batch file that will re-start an application on a 2 state condition i.e. when a ping fails and then recovers. I've written something gleaned from information given on this site (see below) that just restarts it when it fails and changes the DOS prompt colour, but it's not ideal. Can anyone point me in the general direction to restart the app on a down -> up condition with a ping? Many thanks!
#echo off
cls
set INTERVAL=120
:top
ping -n 1 -w 2000 192.168.1.10 | find "TTL="
IF ERRORLEVEL 1 (SET OUT=4F & echo Request timed out.) ELSE (SET OUT=2F)
IF ERRORLEVEL 1 goto reset
COLOR %OUT%
ping -n 2 -l 100 127.0.0.1 >nul
goto top
:reset
timeout %INTERVAL%
taskkill /IM VmsClientApp.exe /F
Ping -n 1 -l 256 127.0.0.1 >nul
start /D "c:\Program Files\Avigilon\Avigilon Control Center Client\" VmsClientApp.exe
echo The Client is now loading...
goto top
#echo off
setlocal enableextensions disabledelayedexpansion
set "interval=120"
cls
:up
color 2f
set "down="
:test
ping -n 1 -w 2000 192.168.1.10 | find "TTL="
if not errorlevel 1 if defined down goto :restart
if errorlevel 1 set "down=1" & color 4f
timeout %interval%
goto :test
:restart
taskkill /IM VmsClientApp.exe /F
start "" /D "c:\Program Files\Avigilon\Avigilon Control Center Client" VmsClientApp.exe
goto :up
I want to tell a user to input just how many minutes he wants before shutting down the computer and I don't know how can I avoid any letter in the user input. I just want to allow a number otherwise go to finish
#ECHO OFF
pushd %systemroot%
echo *{Enter the number of minutes required before Turn off the computer then press (enter)}
set/p "x="
if %x% EQU %x% set/a z= 60*%x%
echo %z%
shutdown -s -t %z%
echo finish
Here is another method:
#ECHO OFF
pushd "%systemroot%"
:loop
"set x="
set /p "x=Enter the number of minutes required before Turn off the computer then press (enter) "
rem this allows the user to press enter to quit without doing anything
if not defined x goto :EOF
rem check for numerals only - else loop to start again
set "num="
for /f "delims=0123456789" %%a in ("%x%") do set "num=%%a"
if defined num goto :loop
set /a z=60*%x%
echo %z%
shutdown -s -t %z%
echo finish
#ECHO OFF
SETLOCAL
pushd %systemroot%
echo *{Enter the number of minutes required before Turn off the computer then press (enter)}
set/p "x="
SET "notnumber=9%x%"
FOR /l %%z IN (0,1,9) DO CALL SET "notnumber=%%notnumber:%%z=%%"
IF DEFINED notnumber ECHO entry was NOT a number&GOTO :EOF
set/a z= 60*%x% 2>NUL
IF ERRORLEVEL 1 ECHO invalid number entered&GOTO :EOF
echo %z%
ECHO shutdown -s -t %z%
echo finish
GOTO :eof
Note that batch regards a number that starts 0 as OCTAL, so entering 09 is invalid (because it's not octal) and entering 013 is valid, but will give a timeout of 11 minutes because 13 octal is 11 decimal.
Note also that the shutdown command is simply echoed to avoid shutting down during testing.
I have an issue and can't seem to see where I am going wrong.
I have this code, that is meant to loop through a text file, and look at the last word of the line to see if the user at the start of the line should receive elevated access to their assigned laptop.
However the code just runs through once, and then exits.
#echo off
cls
echo.
echo The following script will process the entire list of students, giving each
echo student administration rights to the laptop and set the laptop description
echo where necessary.
echo.
pause
cls
FOR /F "tokens=1-6 delims=," %%a IN (accesselevations.txt) DO (
set School1=%%a
set LaptopID=%%b
set Model1=%%c
set Serial1=%%d
set User1=%%e
set Access1=%%f
If /i "%%f" EQU "Admin" goto Elevate2
If /i "%%f" EQU "NoAdmin" goto NoElevate2
:Elevate2
set Desc1=!School1! - !LaptopID! - !Model1! - !Serial1! - !User1!
echo.
echo Now creating local admin account for !user! on !LaptopID!
echo.
echo Description: !Desc1!
echo.
pause
psexec \\!LaptopID! -u GBN\!ocusr! -p !ocpw! -n 10 -e net localgroup Administrators "GBN\!User1!" /add
psexec \\!LaptopID! -u GBN\!ocusr! -p !ocpw! -n 10 -e net config server /srvcomment:"!Desc1!"
:NoElevate2
cls
Echo.
Echo User !user1! is not allowed Local Administrator rights on !LaptopID!.
pause
)
pause
:End
The file AccessElevations has confidential data in it so I am not able to post it unfortunately, however it contains something like this
School,WorkstationID,LaptopModel,LaptopSerial,StudentUsername,AdminOrNot
School,WorkstationID,LaptopModel,LaptopSerial,StudentUsername,AdminOrNot
School,WorkstationID,LaptopModel,LaptopSerial,StudentUsername,AdminOrNot
School,WorkstationID,LaptopModel,LaptopSerial,StudentUsername,AdminOrNot
...and so-on.
I hope I have given enough information, I'm fairly new here.
Thanks in advance for any light you can spread on the issue.
Toby
Use setlocal enabledelayedexpansion or you won't able to use exclamation point on variables.
Close your FOR loop before Elevate2
Change this:
If /i "%%f" EQU "Admin" goto Elevate2
If /i "%%f" EQU "NoAdmin" goto NoElevate2
To:
If /i "%%f" EQU "Admin" (CALL:Elevate2) else (CALL:NoElevate2)
Using CALL command, your script will return to the end of FOR loop after elevation operation is done, GOTO command connot do this.
Put exit/b before :NoElevate2, otherwise your script won'r return to CALL command point.
Your code should be like this:
#echo off
setlocal enabledelayedexpansion
cls
echo.
echo The following script will process the entire list of students, giving each
echo student administration rights to the laptop and set the laptop description
echo where necessary.
echo.
pause
cls
FOR /F "tokens=1-6 delims=," %%a IN (accesselevations.txt) DO (
set School1=%%a
set LaptopID=%%b
set Model1=%%c
set Serial1=%%d
set User1=%%e
set Access1=%%f
If /i "%%f" EQU "Admin" (CALL:Elevate2) else (CALL:NoElevate2))
:Elevate2
set Desc1=!School1! - !LaptopID! - !Model1! - !Serial1! - !User1!
echo.
echo Now creating local admin account for !user! on !LaptopID!
echo.
echo Description: !Desc1!
echo.
pause
psexec \\!LaptopID! -u GBN\!ocusr! -p !ocpw! -n 10 -e net localgroup Administrators "GBN\!User1!" /add
psexec \\!LaptopID! -u GBN\!ocusr! -p !ocpw! -n 10 -e net config server /srvcomment:"!Desc1!"
exit/b
:NoElevate2
cls
Echo.
Echo User !user1! is not allowed Local Administrator rights on !LaptopID!.
pause
exit/b
:End
#echo off
setlocal
cls
echo.
echo The following script will process the entire list of students, giving each
echo student administration rights to the laptop and set the laptop description
echo where necessary.
echo.
pause
cls
FOR /F "tokens=1-6 delims=," %%a IN (accesselevations.txt) DO (
set School1=%%a
set LaptopID=%%b
set Model1=%%c
set Serial1=%%d
set User1=%%e
set Access1=%%f
If /i "%%f" EQU "Admin" CALL :Elevate2
If /i "%%f" EQU "NoAdmin" CALL :NoElevate2
)
GOTO :EOF
:Elevate2
set Desc1=%School1% - %LaptopID% - %Model1% - %Serial1% - %User1%
echo.
echo Now creating local admin account for %user1% on %LaptopID%
echo.
echo Description: %Desc1%
echo.
ECHO psexec \\%LaptopID% -u GBN\%ocusr% -p %ocpw% -n 10 -e net localgroup Administrators "GBN\%User1%" /add
ECHO psexec \\%LaptopID% -u GBN\%ocusr% -p %ocpw% -n 10 -e net config server /srvcomment:"%Desc1%"
GOTO :eof
:NoElevate2
Echo.
Echo User %user1% is not allowed Local Administrator rights on %LaptopID%.
GOTO :EOF
Notes:
setlocal added to ensure environment does not get polluted by a run
Doesn't appear to be much point in setting Access1 since it isn't used.
CALL :routine rather than goto - Not a ood idea to goto within a block as some cmd versions appear to work differently. Colon is required for running internal subroutine
Within internal subroutines, can use %var% since these run in their own context.
!var! syntax is only effective when invoked by setlocal enabledelayedexpansion (not executed in original batch.)
psexec commands simply ECHOed. Need to remove the preceding echo to execute the psexec
Shouldn't a 'remove privileges' routine be applied for 'Nodamin' ?
!user! changed to %user1% in :elevate2 since user1 is established by the loop, not user.
Suitable datafile used for testing was:
School1,Workstation1ID,Laptop1Model,Laptop1Serial,Student1Username,Admin
School2,Workstation2ID,Laptop2Model,Laptop2Serial,Student2Username,NoAdmin
School3,Workstation3ID,Laptop3Model,Laptop3Serial,Student3Username,Admin
School4,Workstation4ID,Laptop4Model,Laptop4Serial,Student4Username,NoAdmin
not that hard to construct - could easily be done with a prettier version by substituting for names and other sensitive information.
I want to make a batch file that waits for a few minutes, then executes a command. How would I do this? Specifically, I want it to end another program in 3 minutes after opening the file.
Use timeout. That will let you wait for a number of seconds given in it's /t parameter. timeout /t 180 will sleep for 3 minutes (180 seconds).
TIMEOUT [/T] timeout [/NOBREAK]
Description:
This utility accepts a timeout parameter to wait for the specified
time period (in seconds) or until any key is pressed. It also
accepts a parameter to ignore the key press.
Parameter List:
/T timeout Specifies the number of seconds to wait.
Valid range is -1 to 99999 seconds.
/NOBREAK Ignore key presses and wait specified time.
/? Displays this help message.
NOTE: A timeout value of -1 means to wait indefinitely for a key press.
Examples:
TIMEOUT /?
TIMEOUT /T 10
TIMEOUT /T 300 /NOBREAK
TIMEOUT /T -1
Another method is to ping an invalid IP address for a certain amount of time:
PING 1.1.1.1 -n 1 -w 60000 >NUL
60000 = milliseconds
hi i love stockoverflow but sometimes the answers are too concise... so heres more than you asked for... the timer and many other snipits
#ECHO off
MODE CON:COLS=25 LINES=11
cls
color 0B
:taskkill
echo.
echo Program To Shutdown
echo.
set /p taskkill=
if "%taskkill%" == "%taskkill%" goto taskkillconfirm
exit
:taskkillconfirm
color 0B
:image
set image=/im
if "%image%" == "%image%" goto imageconfirm
exit
:imageconfirm
color 0B
:forced
set forced=/f
if "%forced%" == "%forced%" goto forcedconfirm
exit
:forcedconfirm
cls
:hour
color 0B
echo.
echo. Hours?
echo.
set /p hour=
:min
color 0B
cls
echo.
echo Minutes?
echo.
set /p min=
:sec
color 0B
cls
echo.
echo Seconds?
echo.
set /p sec=
:continue
color 0B
cls
echo %taskkill%
echo Program Shutdown in
echo %hour% Hours
echo %min% Minutes
echo %sec% Seconds
set /a sec="%sec%-1"
if %sec%==-1 set /a min="%min%-1"
if %sec%==-1 set /a sec="59"
if %min%==-1 set /a hour="%hour%-1"
if %min%==-1 set /a min="59"
if %hour%==-1 goto done
ping -n 2 127.0.0.1 >NUL
goto continue
:done
color 0B
cls
taskkill %image% %taskkill% %forced%
exit
hope you really enjoy this answer
Simple, try this
#echo off
echo Do you want to read word file or pdf file? Hit any key for options...
pause >nul
echo w for word
echo p for pdf
::set input =
set /p input = Choose your option
if %input% == w goto w
if %input% == p goto p
:w
echo Reading Word file...
::start /your/path/to/your/Office/winword.exe
/path/to/your/doc/file/filename.doc
echo Timer starts
pause >nul
echo 10
ping localhost -n 2 >nul
cls
echo 9
ping localhost -n 2 >nul
cls
echo 8
ping localhost -n 2 >nul
cls
echo 7
ping localhost -n 2 >nul
cls
echo 6
ping localhost -n 2 >nul
cls
echo 5
ping localhost -n 2 >nul
cls
echo 4
ping localhost -n 2 >nul
cls
echo 3
ping localhost -n 2 >nul
cls
echo 2
ping localhost -n 2 >nul
cls
echo 1
ping localhost -n 2 >nul
cls
echo Time's up. Starting the next document...
::you can copy/paste the above commands to start another word file
:p
echo Reading Pdf file...
echo Timer starts
::start /your/path/to/your/Acrobat/acrord32.exe
/path/to/your/pdf/file/filename.pdf
pause >nul
echo 10
ping localhost -n 2 >nul
cls
echo 9
ping localhost -n 2 >nul
cls
echo 8
ping localhost -n 2 >nul
cls
echo 7
ping localhost -n 2 >nul
cls
echo 6
ping localhost -n 2 >nul
cls
echo 5
ping localhost -n 2 >nul
cls
echo 4
ping localhost -n 2 >nul
cls
echo 3
ping localhost -n 2 >nul
cls
echo 2
ping localhost -n 2 >nul
cls
echo 1
ping localhost -n 2 >nul
cls
echo Times up. Starting the next document...
::you can copy/paste the above commands to start another Pdf file