#echo off
timeout /t 2 >NUL
cls
cd %temp%
set "var1=%random%%random%"
echo >%var1%.vbs set shell = CreateObject("WScript.Shell"):shell.SendKeys "%{ENTER}" & %var1%.vbs
pause
This is my code. What I basically want the batch file to do is to open itself up in fully, fully fullscreen (im talking f11 fullscreen mode). You can fullscreen a batch file on windows 10 with ALT+ENTER. So I write vbs send keys to do that... The % and ENTER is to send ALT+ENTER... when ran, I don't get an error with the vbs... just no fullscreen... why?
I created this batch and i tested it on my Windows 10 and it works 5/5
#echo off
Set "MyTitle=FullScreen"
Title %MyTitle% & color 0A & cls & cd %temp%
set "vbsfile=%~n0.vbs"
echo >"%vbsfile%" set shell = CreateObject("WScript.Shell"):shell.SendKeys "{F11}"
REM Timeout /t 1 /nobreak>NUL
Wscript.exe "%vbsfile%"
Ipconfig /all
pause
And here is another batch that can use this as sub to be called when you want to fullscreen or come to the back to normal screen :
#echo off
REM Here we call the sub :FullScreen to make it fullscreen
Call :FullScreen
Ping www.google.com
Tracert www.google.com
Call :FullScreen REM You come to the normal when we call it again the sub :FullScreen
ipconfig /all
Pause & Exit
REM -------------------------------------------------------------------------------
:FullScreen
Set "MyTitle=FullScreen"
Title %MyTitle% & color 0A & cls & cd %temp%
set "vbsfile=%~n0.vbs"
echo >"%vbsfile%" set shell = CreateObject("WScript.Shell"):shell.SendKeys "{F11}"
REM Timeout /t 1 /nobreak>NUL
Wscript.exe "%vbsfile%"
Exit /b
REM -------------------------------------------------------------------------------
Related
I have a batch file that will run a macro. The macro will automatically run all day but I want to be able to start and stop it with a simple keyboard character. Is there a way in the code that I can add a "Press S to stop, and R to Resume"? The resume would start my vbs file again.
powershell -window minimized -command ""
#echo off
pause
cls
:start
cscript DisplayBoard2.vbs "S:\filepath\macro.xlsm"
goto start
You can use the choice command to do what you want.
Note: the script window has to be active for it to work. Cmd has no possibility to "intercept" keypresses if the window is not active.
#echo OFF
:start
echo running. Press 'S' to suspend.
REM your payload here
choice /c SX /n /t 1 /d X >nul
if errorlevel 2 goto :start
:pause
echo paused. Press 'R' to resume.
choice /c RX /n /t 1 /d X >nul
if errorlevel 2 goto :pause
goto :start
What (I guess) you really want, is called a keylogger (to catch keyboard input regardless of what application has the focus). See this site for how it basically works.
I have made a program in notepad which when runs allows the user to choose one of a select amount of options. Each option is a time that essentially counts down until when it hits 0 the computer locks itself.
Problems:
This has been created to allocate a set amount of time for my little brother however it can easily be stopped by just manually closing the program.
I wanted to know if I could therefore make it so after choosing an option the program would hide itself by running in the background or so if it is manually closed it would reopen and carry on counting down thank you.
Provided Example Code:
#echo off
cls
title Shutdown timer
color 0a
:start
echo
echo Choose Your Time allocated
echo 1. 35 Minutes
echo 2. 65 Minutes
echo 3. 95 Minutes
echo 4. 125 Minutes
echo 5. 1 Minutes
set /p choice=Type which number for your choice
if not '%choice%'== set choice=%choice:~0,1%
if '%choice%'=='1' goto :Choice1
if '%choice%'=='2' goto :Choice2
if '%choice%'=='3' goto :Choice3
if '%choice%'=='4' goto :Choice4
If '%choice%'=='5' goto :Choice5
echo "%choice%" is not a valid option. Please try again
You're looking to baby-poof a batch script? A simple solution is to simply hide the command window. This can be done by using a .VBS command shell to hide the command prompt process. Original post here.
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
Above is the script to hide command windows in VBS. You can use this script by calling wscript.exe "Script" "Batch File". Pretty simple and easy way to do it without 3'rd party tools.
I combined your script to allow to create, export, use, and delete these files. Your Main shutdown script will also need exported to a new batch file to be called to by the VBS script. This can be done using a code block bellow
Rem | Create Timer.bat
(
Echo TIMEOUT /T %Time% /NOBREAK
Echo rundll32.exe user32.dll,LockWorkStation
Echo DEL "%%~f0"
)>> %Temp%\Timer.bat
This will create a new batch file containing the shutdown or lock commands. In this case rundll32.exe user32.dll,LockWorkStation will lock the workstation after X minutes by TIMEOUT /T
StartTimmer.bat:
#echo off
title Shutdown timer
color 0a
:start
cls
echo Choose Your Time allocated:
echo(
echo 1. 35 Minutes
echo 2. 65 Minutes
echo 3. 95 Minutes
echo 4. 125 Minutes
echo 5. 1 Minutes
echo(
set /p "choice=Type which number for your choice: "
if "%choice%"=="1" set "choice=35" & goto ChoiceSellected
if "%choice%"=="2" set "choice=65" & goto ChoiceSellected
if "%choice%"=="3" set "choice=95" & goto ChoiceSellected
if "%choice%"=="4" set "choice=125" & goto ChoiceSellected
If "%choice%"=="5" set "choice=1" & goto ChoiceSellected
goto start
:ChoiceSellected
Echo Now Starting Timmer For %choice% Minutes
Rem | Do math - Covert Seconds To Minutes
Set /a "Time=%choice% * 60"
Rem | Create Timer.bat
(
Echo TIMEOUT /T %Time% /NOBREAK
Echo rundll32.exe user32.dll,LockWorkStation
Echo DEL "%%~f0"
)>> %Temp%\Timer.bat
Rem | Export Hide Script & Use it
Echo CreateObject^("Wscript.Shell"^).Run """" ^& WScript.Arguments^(0^) ^& """", 0, False>> Hide.vbs
wscript.exe "%~dp0Hide.vbs" "%Temp%\Timer.bat"
del "%~dp0Hide.vbs"
goto :EOF
For help on any of the commands do the following:
call /?
set /?
for /?
if /?
find /?
So on.
I have created the below code to execute multiple commands depending on the user input but the input is case-sensitive.
I have tried the /I switch with the if statement but that does not work either.
Below is the code:
#Echo off
SET /P uname=Launch Outlook in safe mode:
IF "%uname%"==Yes GOTO Error
IF "%uname%"==No GOTO start
:Error
taskkill /IM Outlook.exe /f
cd c:\Program Files (x86)\Microsoft Office\root\Office16
start Outlook.exe /safe
#echo The Script is running please wait && timeout /t 20
taskkill /IM Outlook.exe /f
cd %Homepath%
cd Appdata\Local\Temp
echo.>myfile.txt && #echo Thanks for using the script,You may close this window.and continue. > myfile.txt
start outlook.exe
timeout /t 8
start notepad myfile.txt
:End
:start
echo "No valid options"
echo "This window would close in 10 seconds" && timeout /t 10
:End
I would use the choice command instead
echo Y] Yes
echo N] No
choice /c yn /n
if %errorlevel%==1 goto yes
if %errorlevel%==2 goto yes
I want to manage to execute and manipulate my bat file, but, în background i want a countdown so that after a specific time, no matter what, my bat calls another one that deletes it, or simply closes.
Also i want the bat file to show up on execution maximized. I have set /max after start command, but still minimized. I used în my bat /min and it worked, cant figure out why /max doesent work.
To make it start maximized put this at the top of your script, below #echo off
if not "%1" == "max" start /MAX cmd /c %0 max & exit/b
I'll update this answer later with the other part, but I think opening a new batch with a timeout as soon as this one starts with start /B should help a lot.
EDIT
So this starts your script with a second script in it. That second script kills the first script and starts a third cmd to delete itself:
#echo off
if not "%1" == "max" start /MAX cmd /c %0 max & exit/b
set T=%TEMP%\sthUnique.tmp
wmic process where (Name="WMIC.exe" AND CommandLine LIKE "%%%TIME%%%") get ParentProcessId /value | find "ParentProcessId" >%T%
set /P A=<%T%
SET PID=%A:~16%
echo #echo off > killParent.bat
:: replace the 5 on the next line with any other number
echo timeout /t 5 /nobreak >> killParent.bat
echo start "" cmd ^/c timeout ^/t 1^^^&del "%%~f0"^^^&exit ^/b >> killParent.bat
echo taskkill /f /PID %PID% >> killParent.bat
START /B CMD /C CALL killParent.bat >NUL 2>&1
::any logic here instead of pause
pause
Place your code where the pause is and replace the 5 with the number of seconds you want to wait.
This does have the drawback of not being able to finish before the timer runs out, you can fix that by putting echo title parentKiller >> killParent.bat below echo #echo off > killParent.bat and putting
del killParent.bat
taskkill /F /FI "WINDOWTITLE eq parentKiller *" /T
at the end of your execution path, so at the bottom of your batch file normally. This would then look like this:
#echo off
if not "%1" == "max" start /MAX cmd /c %0 max & exit/b
set T=%TEMP%\sthUnique.tmp
wmic process where (Name="WMIC.exe" AND CommandLine LIKE "%%%TIME%%%") get ParentProcessId /value | find "ParentProcessId" >%T%
set /P A=<%T%
SET PID=%A:~16%
echo #echo off > killParent.bat
echo title parentKiller >> killParent.bat
:: replace the 5 on the next line with any other number
echo timeout /t 5 /nobreak >> killParent.bat
echo start "" cmd ^/c timeout ^/t 1^^^&del "%%~f0"^^^&exit ^/b >> killParent.bat
echo taskkill /f /PID %PID% >> killParent.bat
START /B CMD /C CALL killParent.bat >NUL 2>&1
::any logic here instead of pause
pause
del killParent.bat
taskkill /F /FI "WINDOWTITLE eq parentKiller *" /T
How do I create a batch file timer to execute / call another batch through out the day Maybe on given times to run but not to run on weekends ? Must run on system times can also be .cmd to run on xp server 2003
For the timer part of your script i highly reccomend using:
echo.
echo Waiting For One Hour...
TIMEOUT /T 3600 /NOBREAK
echo.
echo (Put some Other Processes Here)
echo.
pause >nul
This script waits for 1 hour (3600 seconds) and then continues on with the script and the user cannot press any buttons to bypass the timer (besides CTRL+C).
You can use
Timeout /t 3600 /nobreak >nul
If you don't want to see a countdown on the screen.
I would use the scheduler (control panel) rather than a cmd line or other application.
Control Panel -> Scheduled tasks
Below is a batch file that will wait for 1 minute, check the day, and then perform an action. It uses PING.EXE, but requires no files that aren't included with Windows.
#ECHO OFF
:LOOP
ECHO Waiting for 1 minute...
PING -n 60 127.0.0.1>nul
IF %DATE:~0,3%==Mon CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Tue CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Wed CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Thu CALL WootSomeOtherFile.cmd
IF %DATE:~0,3%==Fri CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Sat ECHO Saturday...nothing to do.
IF %DATE:~0,3%==Sun ECHO Sunday...nothing to do.
GOTO LOOP
It could be improved upon in many ways, but it might get you started.
The AT command would do that but that's what the Scheduled Tasks gui is for. Enter "help at" in a cmd window for details.
I did it by writing a little C# app that just wakes up to launch periodic tasks -- don't know if it is doable from a batch file without downloading extensions to support a sleep command. (For my purposes the Windows scheduler didn't work because the apps launched had no graphics context available.)
#echo off
:Start
title timer
color EC
echo Type in an amount of time (Seconds)
set /p time=
color CE
:loop
cls
ping localhost -n 2 >nul
set /a time=%time%-1
echo %time%
if %time% EQU 0 goto Timesup
goto loop
:Timesup
title Time Is Up!
ping localhost -n 2 >nul
ping localhost -n 2 >nul
cls
echo The Time is up!
pause
cls
echo Thank you for using this software.
pause
goto Web
goto Exit
:Web
rem type ur command here
:Exit
Exit
goto Exit
#echo off
:Start # seting a ponter
title timer #name the cmd window to "Timer"
echo Type in an amount of time (Seconds)
set /p A= #wating for input from user
set B=1
cls
:loop
ping localhost -n 2 >nul #pinging your self for 1 second
set /A A=A-B #sets the value A - 1
echo %A% # printing A
if %A% EQU 0 goto Timesup #if A = 0 go to ponter Timesup eles loop it
goto loop
:Timesup #ponter Timesup
cls #clear the screen
MSG * /v "time Is Up!" #makes a pop up saying "time Is Up!"
goto Exit #go to exit
:Exit
better code that doesn't involve ping:
SET COUNTER=0
:loop
SET /a COUNTER=%COUNTER%+1
XCOPY "Server\*" "c:\minecraft\backups\server_backup_%COUNTER%" /i /s
timeout /t 600 /nobreak >nul
goto loop
600 seconds is 10 minutes, however you can set it whatever time you'd like
You could also do this>
#echo off
:loop
set a=60
set /a a-1
if a GTR 1 (
echo %a% minutes remaining...
timeout /t 60 /nobreak >nul
goto a
) else if a LSS 1 goto finished
:finished
::code
::code
::code
pause>nul
Or something like that.