Start EXE Through Batch File - batch-file

So, I'm trying to setup a basic script to install WinRAR (as my test, others later on) and I' can't seem to get it to work. Here's what I have:
#ECHO OFF
IF EXIST "C:\Program Files (x86)\WinRAR" GOTO End
IF EXIST "C:\Program Files\WinRAR" GOTO End
IF DEFINED ProgramFiles(x86) (
START C:\WinRAR_4.20_(x64).exe
) ELSE (
START C:\WinRAR_4.20_(x86).exe
)
:End
PAUSE
The first two EXIST checks work fine, but I can't get the START command to work. If I just type it out in the CMD window it starts up the installer, but it just wont do it from the batch file.
Can someone point me to where I'm screwing up?

The problem is with the FileName. Get rid of parenthesis in the file name and it should work fine. WinRAR_4.20_x64.exe and WinRAR_4.20_x86.exe

the start command requires a string for the title of the window, for instance,
start "" apples.exe
will start apples.exe with the title of the console window as
currently you are telling the start script that the title of the console window should be:
C:\WinRAR_4.20_(x64).exe
You should type in the following:
start "" "C:\WinRAR_4.20_(x64).exe"

It worked on first time only.Non of this options.
start "" C:\Program Files (x86)\MSI\Command Center\CommandCenter.exe
2)START /d start "C:\Program Files (x86)\MSI\Command Center" CommandCenter.exe

Related

Hide Open Program With CMD

Hello I would like to know if someone can help me I would like to know how to open a program and this is hidden (not shown in the taskbar) I was testing the following but it did not work Anyone have any other ideas?
Start /b "Título" "word.exe"
If you are simply trying to start a program from the command prompt you must first locate the file path of the executable
Example:
Assuming word.exe lives in the below directory, cd will change your working directory in the command prompt
cd C:\Program Files\Microsoft Office\root\Office16
Then start the program with
start /B WINWORD.exe
Or as stated in the comments you could just type its registered name:
start winword
start /min winword
/min will not hide it, it will just minimize to the task bar.
To run it hide use VBScript:
Echo Dim sh : Set sh = CreateObject^(Wscript.Shell^) : sh.run """Winword.exe Full Path""", 0, False >tmp.vbs
Cscript //nologo tmp.vbs
Del tmp.vbs

How to run .EXE from .BAT inside the folder where .EXE is locating

To recreate my problem you need to understand that I have next files in 2 folders.
K:\Script.bat
K:\Project\PortChanger.exe
K:\Project\settings.xml
I want to launch PortChanger.exe using Script.bat that contains next line:
start "K:\Project\PortChanger.exe"
This script is actually executing Program.exe, but my program throws me exception since PortChanger.exe can't find Settings.xml.
How can I launch PortChanger.exe from "K:\Project\", not from "K:\"? Now it seems like .BAT taking .EXE code and just running it where .BAT is locating.
To make it even more clear:
You could use Start with its /D option:
Start "" /D "K:\Project" "K:\Project\PortChanger.exe"
Open a Command Prompt window and enter start /? to read its usage information.
I would suggest you rather use pushd and popd
#echo off
pushd "K:\Project"
start "" PortChanger.exe
popd
pushd will change to the directory, launch the executable from it, then popd will return to the previous directory stored.

Create a batch file to run an .exe with an additional parameter

I need a batch file which will do the following:
1. Open CMD and navigate to a location C:/Users/...../program.exe
2. Run the program.exe with an additional command to point it to a config file:
e.g. "program.exe C:/Users/..../configFile.bgi"
How can I do this?
I tried this but with no luck:
start "C:\Users\Ben\Desktop\BGInfo\bginfo.exe C:\Users\Ben\Desktop\BGInfo\dc_bginfo.bgi"
pause
Update
I've used the solution provided by Ganesh (below) and came up with this:
cd C:\Users\Ben\Desktop\BGInfo\
bginfo.exe C:\Users\Ben\Desktop\BGInfo\dc_bginfo.bgi
I've tested it on a local machine (changing the directories) but on the server (with the directory above) it does not work...
The folder directory with batch file:
The error
in batch file abc.bat
cd c:\user\ben_dchost\documents\
executible.exe -flag1 -flag2 -flag3
I am assuming that your executible.exe is present in c:\user\ben_dchost\documents\
I am also assuming that the parameters it takes are -flag1 -flag2 -flag3
Edited:
For the command you say you want to execute, do:
cd C:\Users\Ben\Desktop\BGInfo\
bginfo.exe dc_bginfo.bgi
pause
Hope this helps
You can use
start "" "%USERPROFILE%\Desktop\BGInfo\bginfo.exe" "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi"
or
start "" /D "%USERPROFILE%\Desktop\BGInfo" bginfo.exe dc_bginfo.bgi
or
"%USERPROFILE%\Desktop\BGInfo\bginfo.exe" "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi"
or
cd /D "%USERPROFILE%\Desktop\BGInfo"
bginfo.exe dc_bginfo.bgi
Help on commands start and cd is output by executing in a command prompt window help start or start /? and help cd or cd /?.
But I do not understand why you need a batch file at all for starting the application with the additional parameter. Create a shortcut (*.lnk) on your desktop for this application. Then right click on the shortcut, left click on Properties and append after a space character "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi" as parameter.
Found another solution for the same. It will be more helpful.
START C:\"Program Files (x86)"\Test\"Test Automation"\finger.exe ConfigFile="C:\Users\PCName\Desktop\Automation\Documents\Validation_ZoneWise_Default.finger.Config"
finger.exe is a parent program that is calling config solution.
Note: if your path folder name consists of spaces, then do not forget to add "".

.BAT - IF command do not work

Ok, so probably I am doing something ultra wrong.
I want to make this:
in C:\programs\app\install.exe
is installation of a program.
It should install to:
c:\program files\app
And my question is how to make IF command inside .bat file to:
if c:\program files\app\appStart.exe exist start c:\program files\app\appStart.exe
if c:\program files\app\appStart.exe not exist start C:\programs\app\install.exe
to make it more simple I test it on this files in this folder (never tried with folders and files from above)
c:\folder\1.txt
c:\folder\2.txt
c:\folder\A.txt
c:\folder\B.txt
And I want to make:
if c:\folder\1.txt exist start c:\folder\A.txt
if c:\folder\1.txt not exist start c:\folder\B.txt
I found tons of sites on google with answers but nothing seems to work to me they won't even open.
Was trying this:
IF EXIST "C:\Nowy folder" (
REM 1.txt
IF EXIST "1.txt" (Start "C:\folder\1.txt") ELSE (Start "C:\folder\A.txt")
) ELSE (
REM 2.txt
IF EXIST "2.txt" (Start "C:\folder\2.txt") ELSE (Start "C:\folder\B.txt")
)
Pause&Exit
or this
if exist "%CD%\1.txt" (Start /wait "%CD%\A.txt") ELSE Start /wait "%CD%\B.txt"
Pause
Also doesn't work.
It is no matter if I give full path or %CD% it just doesn't work.
Anyone can tell me what I am doing wrong ?
if exist "c:\program files\app\appStart.exe" ( start "" "c:\program files\app\appStart.exe"
) else (start "" "C:\programs\app\install.exe")
You need to "quote names containing spaces" and the first quoted parameter to START becomes the window-title, so you'd put an empty-quoted string for the first parameter (or "whatever window title you want")
I'm confused about the remainder of your question. Have you a further question?
This checks for both the exe files and will use the first one in preference to the second exe.
#echo off
if exist "c:\program files\app\appStart.exe" (
start "" "c:\program files\app\appStart.exe"
) else (
if exist "C:\programs\app\install.exe" start "" "C:\programs\app\install.exe"
)

How do I execute cmd commands through a batch file?

I want to write a batch file that will do following things in given order:
Open cmd
Run cmd command cd c:\Program files\IIS Express
Run cmd command iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
Open Internet Explorer 8 with URL= http://localhost:8088/default.aspx
Note: The cmd window should not be closed after executing the commands.
I tried start cmd.exe /k "cd\ & cd ProgramFiles\IIS Express", but it is not solving my purpose.
So, make an actual batch file: open up notepad, type the commands you want to run, and save as a .bat file. Then double click the .bat file to run it.
Try something like this for a start:
c:\
cd c:\Program files\IIS Express
start iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
start http://localhost:8088/default.aspx
pause
I think the correct syntax is:
cmd /k "cd c:\<folder name>"
This fixes some issues with Blorgbeard's answer (but is untested):
#echo off
cd /d "c:\Program files\IIS Express"
start "" iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
timeout 10
start http://localhost:8088/default.aspx
pause
cmd /c "command" syntax works well. Also, if you want to include an executable that contains a space in the path, you will need two sets of quotes.
cmd /c ""path to executable""
and if your executable needs a file input with a space in the path a another set
cmd /c ""path to executable" -f "path to file""
#echo off
title Command Executer
color 1b
echo Command Executer by: YourNameHere
echo #################################
: execute
echo Please Type A Command Here:
set /p cmd=Command:
%cmd%
goto execute
start cmd /k "your cmd command1"
start cmd /k "your cmd command2"
It works in Windows server2012 while I use these command in one batch file.
cmd /k cd c:\
is the right answer
I was trying to run a couple of batch files parallely at startup, if a condition was true.
For this I made a parent batch file which should have checked for the condition and invoke the other child batch files if the condition was true.
I tried to achieve it via START but it gave me an empty black command prompt running in the directory of children batch files, instead of running the children batch files themselves
The thing which worked for me was by using a combination of START and CALL
As an example
condition ...
start call "C:\Users\Amd\conn\wsl_setup - conn1.bat"
start call "C:\Users\Amd\conn\wsl_setup - conn2.bat"
start call "C:\Users\Amd\conn\wsl_setup - conn3.bat"
I know DOS and cmd prompt DOES NOT LIKE spaces in folder names. Your code starts with
cd c:\Program files\IIS Express
and it's trying to go to c:\Program in stead of C:\"Program Files"
Change the folder name and *.exe name. Hope this helps

Resources