So I have a batch file that I am trying to convert but i'm no success. The converter that I am using is
Bat To Exe Converter. The problem that I am encountering is that after converting the batch file it does not execute properly and immediately says "Press any key to continue . . ." and then closes. The batch file works fine on its own and when I converted it using the websites online converter it also worked (I would use the online but has little functions and is not exactly what I need).
Below is the batch code that I am using:
#ECHO OFF
TITLE ADB Over Network Running...
COLOR 17
CLS
IF "%ANDROID_PLATFORM_TOOLS%" == "" GOTO NOPATH
ADB tcpip 5555
IF ERRORLEVEL 1 GOTO END
IF ERRORLEVEL 0 GOTO NEXT
GOTO END
:NEXT
set /P ip=Enter Devices IP: %=%
ADB connect %ip%
GOTO END
:NOPATH
ECHO "ANDROID_PLATFORM_TOOLS" not found. Please add this environment variable
GOTO END
:END
PAUSE
EXIT
I hope that you can help me. Thank you for any help and your time :D
As all that program does is extract the batch file into a subfolder of temp and execute it, Windows has the exact same feature.
Type
iexpress
in Start - Run and follow the wizard and set your bat to run as the last step.
Related
I have a batch file which requires 4 command line inputs. When I execute the batch file on the command prompt, it displays help message asking to input 4 values.
When I run this file directly from the folder, it opens cmd and closes immediately.
Is it possible to modify the batch file, so that when I run from folder it will open the cmd and then display the help message.?
Following is a mini version of my problem with 1 command input. The script is for a License file generation
#ECHO OFF
GOTO :continue
:continue
SETLOCAL
IF "%1" == "" GOTO :Help
::Set the Command Line Options
SET ARVERSION=%1
::Create Directory
SET OUT_PATH=%cd%
ECHO Initiating Generation...
if not exist %OUT_PATH% mkdir %OUT_PATH%
::Create License File - Calling 'Subs' will create the output with actual Version
Subs ARVERSION %ARVERSION% Input.txt 1>%OUT_PATH%\License.txt
ECHO Scripts are created # %OUT_PATH%
ECHO Generation Completed...
GOTO :End
:Help
ECHO Starting License File Generation...
ECHO Usage:
ECHO InstallerScriptGen.bat AR_VERSION
ECHO AR_VERSION - Version (3.2 or 4.0 or 4.2)
ECHO Example : InstallerScriptGen.bat 3.2.2
ECHO Please Note that input of incorrect values will result in wrong generation.
:End
ENDLOCAL
"Running directly from the folder" (by which I assume you mean "clicking on the icon from within Windows Explorer") causes Windows Explorer to execute the equivalent of CMD /C <<batchfilename>>. When invoked with /C, CMD exits (and the CMD window closes) as soon as the batch file ends. You can force the window to stay open long enough to read the output by ending the script with either the PAUSE command (which will cause it to wait for the user to press any key), or the TIMEOUT command (which will wait the indicated number of seconds before continuing, without a keypress). See SS64's help for the PAUSE and TIMEOUT commands for more information.
Okay, I have such a batchfile:
#title RUBY ;)
#set PATH=D:\Programming\Ruby22-x64\bin;%PATH%
#call cmd /K cd /D E:\RubyProgramming
that I use to facilitate running scripts without the need to navigate to the folder each time. The thing is that I usually run the very same command for hundreds of times for a given program that I am working on at any given time. For instance:
ruby rubyprogram.rb inputfile.txt outputfile.xml miscargument
Is there a way to make such a batch file that types in a command when you run it? Not executes, just type in, so that I press Enter to execute it and use ↑ up arrow to use it again in the cmd? I haven't been able to find a command that would allow this anywhere, but it would be useful if there was one.
The simplest would be to just create a new batch-file that executes that specific command:
#echo off
title RUBY ;)
set PATH=D:\Programming\Ruby22-x64\bin;%PATH%
cd /D E:\RubyProgramming
rubyprogram.rb inputfile.txt outputfile.xml miscargument
Alternatively, you could get the batch file to repeatedly ask for the command to run
#echo off
title RUBY ;)
set PATH=D:\Programming\Ruby22-x64\bin;%PATH%
cd /D E:\RubyProgramming
set RUBYCMD=rubyprogram.rb inputfile.txt outputfile.xml miscargument
:loop
echo.
REM line below ends with a space for neatness
set /p RUBYCMD=Enter ruby command (or 'Q' to exit) [%RUBYCMD%]:
if /i "%RUBYCMD%" == "q" goto :eof
%RUBYCMD%
goto :loop
No, batch files can't type or click anything. However, you can call scripts from a batch file which are written in other languages. For example, you cold write a VB or an AutoIt script, call it from your batch and make the new script "type" the command.
Take a look at this VB script:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\notepad.exe"
WshShell.AppActivate "Notepad"
WshShell.SendKeys "hello world"
This will open notepad, focus the new window and type hello world. This way you can also start a new console or get the focus of an already started one and type your command. This code can be saved in a separate vb script file and called from your batch.
I'm trying to make a simple batch file that will let me pick from a list of programs and run them based on my choice. For reference this is what I have so far:
#echo off
:menu
echo 1. zsnes
echo 2. Project64
echo 3. MAME
echo 4. PCSX2
echo 5. VBA
echo 6. DOSBox
set /p emu=Pick your emulator [1-6]:
if %emu%=1 goto zsnes
if %emu%=2 goto project64
if %emu%=3 goto mame
if %emu%=4 goto pcsx2
if %emu%=5 goto vba
if %emu%=6 goto dosbox
:zsnes
start /d "C:\Users\*username*\Documents\zsnes\" zsnesw.exe
I've just typed out through the zsnes program to test it. The command prompt launches and will ask for me to pick a choice. When I select 1, cmd.exe instantly closes but the program is not run. I made a script that contained only the start line and it worked fine. When I open cmd.exe manually and type that line in it also works fine. It just doesn't work in the context of my script. What could be causing this? Any advice would be greatly appreciated!
because your if is not correct .
Try with
if %emu% == 1 goto zsnes
or
if %emu% equ 1 goto zsnes
and so on.
Some syntax errors in IF and FOR commands leads force exist of the script.
probably you'll want also
:zsnes
start /d "C:\Users\*username*\Documents\zsnes\" zsnesw.exe
goto :eof
to avoid executuion of the code under the other labels.
write the following line at the end of the code or where you want to stop / pause your cmd.exe
timeout \t -1
this will pause your cmd screen and give you an option to close it by asking Yes/No ?.
Exactly like the one before me said, "if" should be:
if %emu% == 1 goto zsnes
Additionally, add "pause" after your batch, so you can read the error-messages when something fails.
I am trying to create a batch file that will reopen my KnockKnockClient and KnockKnockServer programs , get them started.
So far , my batch file looks like this :
#echo off
setlocal
start cmd
start java KnockKnockServer
ping 192.0.2.2 -n 1 -w 5000 > null
start /wait java KnockKnockClient
if errorlevel 1 goto retry
echo Finished successfully
exit
:retry
Also, suppose that I want it to restart so that the CMD window with the KnockKnockClient is active. Is that possible ?
any tips appreciate, thank
"start" itself invokes cmd.
you don't need to give "start cmd"
Maybe your directory path should be varied. (locate correct path of your program)
The last line in my batch file is pause. Is there any way to add a if condition to see if the script is run within command prompt or by double clicking to execute? I want to skip pause if it's running in command prompt.
...
...
if not RUN_IN_COMMAND_PROMPT (
pause
)
EDIT:
Hope to find a solution works in Windows Server 2003/2008, WinXP, Win7.
CALL :GETMYSWITCH %CMDCMDLINE%
IF /I "%MYSWITCH%" == "/C" ECHO I WAS STARTED IN THE EXPLORER & PAUSE
IF /I NOT "%MYSWITCH%" == "/C" ECHO I WAS STARTED IN A DOS SESSION
:GETMYSWITCH
SET MYSWITCH=%2
I know this is a year later but for future people searching you can use
If /I "%COMSPEC%" == %CMDCMDLINE% Goto SkipPause
pause
:SkipPause
It will skip the pause block if running from the command line and pause if running from batch file.
By definition, a shell script is always going to be run in a "command prompt". But try using the SESSIONNAME env var - it seems to NOT be present if the script was started by double-clicking instead of manually running it from a prompt.
Use the tty command.
Use the -s option and check the return value.