Start Firefox from a batch file - 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"

Related

Check arguments in batch file

I'm trying to make a batch script that behave almost like a Linux command in terms of arguments. Here is the idea of the script.
When I run the script with the scenarios described in the code it seems to work fine. The problem that I have is coming when I tried to test the program with wrong parameters. For the 1st parameter being either -manual or -automat and the 2nd parameter being wrong the behave is normal, the program prints "Invalid Argument".
The problem that I encounter is when the 1st argument is not -manual or -automat. In this case I get the error: goto was unexpected at this time.
Does any1 have any idea why this is happening and how can I solve the problem?
#echo off
IF %1!==! goto Result0
IF %1==-manual IF %2!==! goto Result1_manual
IF %1==-automat IF %2!==! goto Result1_auto
IF %1==-manual IF %2==1 goto Result2_manual
IF %1==-manual IF %2==2 goto Result3_manual
IF %1==-automat IF %2==1 goto Result2_auto
IF %1==-automat IF %2==2 goto Result3_auto
:done
echo "Invalid argument"
pause
cmd /k
:Result0
echo "Result0"
pause
cmd /k
:Result1_manual
echo "Result1_manual"
pause
cmd /k
:Result2_manual
echo "Result2_manual"
pause
cmd /k
:Result3_manual
echo "Result3_manual"
pause
cmd /k
:Result1_auto
echo "Result1_auto"
pause
cmd /k
:Result2_auto
echo "Result2_auto"
pause
cmd /k
:Result3_auto
echo "Result3_auto"
pause
cmd /k
If "%1"=="-manual" goto Result1_manual
If parameters might be missing enclose with another character. If %1 in blank and you don't
If ==-manual goto Result1_manual
an illegal syntax, and if you do
If ""=="-manual" goto Result1_manual
a legal syntax that resolves to false.
IF %2!==!
will only be true if %2 is blank. If that is your intention don't use the quote character. It sometimes has special meaning.

Script Shell CMD not running

I running Windows 10 and I can't execute a script shell in .bat
So, my code is:
#echo off
echo .
echo MsgBox "TA MERE"
echo .
echo MsgBox "Salut ca va?"
> msgbox.vbs
cscript msgbox.vbs
loop
So, my script is running but the script do not create msgbox.vbs file on the desktop and the program close the Windows
This is a guess based upon what I think your script is supposed to do:
#echo off
( echo.
echo MsgBox "TA MERE"
echo.
echo MsgBox "Salut ca va?"
)> msgbox.vbs
cscript msgbox.vbs
I've missed out loop because I don't know where you want to loop to.
You can try something like that :
#echo off
REM We create our vbs file in temporary folder
REM If you want to create your vbs file on your desktop
REM Just Replace this line set "VBSFile=%Tmp%\%~n0.vbs" to
REM set "VBSFile=%userprofile%\desktop\%~n0.vbs"
set "VBSFile=%Tmp%\%~n0.vbs"
(
echo MsgBox "TA MERE TOI MEME LOL !",vbExclamation,"TA MERE TOI MEME LOL !"
echo MsgBox "Salut Comment ca va ?",VbQuestion,"TA MERE TOI MEME LOL !"
)> "%VBSFile%"
REM We execute our vbs file
cscript /nologo "%VBSFile%"
REM We Clean our vbs file
Del "%VBSFile%"

start /wait with VeraCrypt Format.exe does not wait until VeraCrypt Format exits

I have a batch project with this one line of code that does not seem to work. Here is the sample code:
#echo off
start /wait System\Engine\InfusedApps\BatchOS.OS.Encryption.x64.x86.free.executable\"VeraCrypt Format.exe" /create OS /password uZhPPGzELNyWLrz3pbC8NFgB /hash whirlpool /encryption AES(Twofish(Serpent)) /filesystem NTFS /size 10G /force
echo part one done
pause
cls
start /wait System\Engine\InfusedApps\BatchOS.OS.Encryption.x64.x86.free.executable\VeraCrypt.exe /q /s /v OS.hc /l Y /p uZhPPGzELNyWLrz3pbC8NFgB
echo part two done
"Part one done" gets echoed before the VeraCrypt Format.exe app terminates. Is there a way to make this work?

bugfixer.bat batch file ask end user which option they want to run

fun stuff!!
Manager has just bought a humdinger of a utility. It does everything. It even has command line functionality. If you run BugFixer /a the application will automatically scan the entire drive for cooties. If you run the Bugfixer /b it will scan all of your files on the Windows\system 32 directory and if you run Bugfixer /c the program will scan and repair your Registry. Need to write a batch file that will allow your users to avoid that pesky GUI and efficiently run the Bug fixer through the command line, by asking them which option they would like to initialize.
:TOP
ECHO WHICH BUG FIXER DO YOU NEED TO RUN? A=ALL B=SOME c=REPAIR
SET /P = %USERSPEC%
IF "%1"=="A=ALL" GO TO :FIRST
IF "%1"=="A=all" GO TO :FIRST
:FIRST
CHKDSK C:
ECHO CHECKING ALL FILES ARE COMPLETE
IF "%2"=="B=SOME" GO TO :NEXT
IF "%2"=="b=some" GO TO :NEXT
:NEXT
CHKDSK /F /R C:\WINDOWS/SYSTEM32
ECHO CHECKING SOME FILES ARE COMPLETE
IF "%3"=="REPAIR" GO TO :LAST
IF "%3"=="repair" GO TO :LAST
:LAST
CHKDSK /c
ECHO REPAIR FILES ARE COMPLETED
Like I said fun stuff. Anyone wanna help?
Next script logic could become helpful:
#echo OFF >NUL
setlocal enableextensions
:TOP
echo(
set "USERSPEC="
set /P "USERSPEC=Which bug fixer do you need to run? A=all B=some C=repair? "
if /I "%USERSPEC%"=="A" goto :FIRST
if /I "%USERSPEC%"=="B" goto :NEXT
if /I "%USERSPEC%"=="C" goto :LAST
echo NO CHECK CHOOSEN, BATCH ENDS
goto :ENDSCRIPT
:FIRST
chkdsk C:
echo CHECKING ALL FILES ARE COMPLETE
goto :TOP
:NEXT
chkdsk /F /R C:\WINDOWS/SYSTEM32
echo CHECKING SOME FILES ARE COMPLETE
goto :TOP
:LAST
chkdsk /c
echo REPAIR FILES ARE COMPLETED
goto :TOP
:ENDSCRIPT
endlocal
goto :eof
However, running it:
==>30019117.bat
Which bug fixer do you need to run? A=all B=some C=repair? a
Access Denied as you do not have sufficient privileges.
You have to invoke this utility running in elevated mode.
CHECKING ALL FILES ARE COMPLETE
Which bug fixer do you need to run? A=all B=some C=repair?
NO CHECK CHOOSEN, BATCH ENDS
==>
Resources (advised reading):
An A-Z Index of the Windows CMD command line (command reference)
Windows CMD Shell Command Line Syntax (additional particularities)
Script resources for IT professionals (a huge Script repository)

Bat file stopping and i'm not sure why

So, I have a bat file I've been building to do a simple profile backup/restore. I'm running Windows 7 64bit.
I get through 99% of the script until it gets to this point and then dies. To be clear, in the environment I'm working in, I HAVE to turn off UAC for certain things. Someone much higher up than me made that call.
However, this needs to do this but it dies after the "[ COMPLETE ]" is echoed. It doesn't close the window, it just goes back to the C prompt.
The only other thing it's going (trying) to do after that is log the user off after a 15 second timer.
Any help would be much appreciated.
echo [ Turning off UAC... ]
C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f
ping -n 2 -w 1000 127.0.0.1 > nul
echo [ COMPLETE ]
ping -n 2 -w 1000 127.0.0.1 > nul
echo.
ECHO ==========================================================
ECHO = Restore Complete =
ECHO = Computer will logoff in 15 seconds to apply changes. =
ECHO ==========================================================
TIMEOUT 16
shutdown /l
#pause
:EOF
I made a test batch file that does what you're trying:
#echo off
echo before
cmd /k echo I'm doing it!
echo after
And here was the result:
C:\files\j>test
before
I'm doing it!
So I changed it to call:
#echo off
echo before
call echo I'm doing it!
echo after
And got this:
C:\files\j>test
before
I'm doing it!
after
So clearly, /k isn't for you. But CALL will put it in a new shell... So my recommendation is to just change that line to be :
%windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f
No cmd, no \k, no anything - just run the REG.exe.
If you have to, use the CALL since you're adding a registry key and it should stay there.

Resources