How to mention C:\Program Files in batchfile - batch-file

I need to invoke an exe file in C:\Program Files directory from a batch file.How can we mention the directory name "Program Files" in batch file.I am getting error like C:\Program not found.
I believe that % or ~ needs to be added in between but couldn't get it.Kindly assist.

Surround the script call with "", generally it's good practices to do so with filepath.
"C:\Program Files"
Although for this particular name you probably should use environment variable like this :
"%ProgramFiles%\batch.cmd"
or for 32 bits program on 64 bit windows :
"%ProgramFiles(x86)%\batch.cmd"

On my pc I need to do the following:
#echo off
start C:\"Program Files (x86)\VirtualDJ\virtualdj_pro.exe"
start C:\toolbetech\TBETECH\"Your Toolbar.exe"
exit

Now that bash is out for windows 10, if you want to access program files from bash, you can do it like so: cd /mnt/c/Program\ Files.

I use in my batch files - c:\progra~2\ instead of C:\Program Files (x86)\ and it works.

I had a similar issue as you, although I was trying to use start to open Chrome and using the file path. I used only start chrome.exe and it opened just fine. You may want to try to do the same with exe file. Using the file path may be unnecessary.
Here are some examples (using the file name you gave in a comment on another answer):
Instead of C:\Program^ Files\temp.exe you can try temp.exe.
Instead of start C:\Program^ Files\temp.exe you can try start
temp.exe

use this as somethink
"C:/Program Files (x86)/Nox/bin/nox_adb" install -r app.apk
where
"path_to_executable" commands_argument

Interestingly with variables ,this worked for me ...
SET "VESTADIR=\\%TARGET%\C$\"Program Files (x86)"\Cassidian\VESTA"

While createting the bat file, you can easly avoid the space. If you want to mentioned "program files "folder in batch file.
Do following steps:
1. Type c: then press enter
2. cd program files
3. cd "choose your own folder name"
then continue as you wish.
This way you can create batch file and you can mention program files folder.

Related

run an exe for self changing name directory batch file

i want to create a portable roblox but these bothers me
i am not so good at batch file but how to i run these exe under these directory i mean
if roblox has an update the "version-3bxxxxxxxx" will change and i cannot run the exe anymore
start "" "C:\Program Files (x86)\Roblox\Versions\version-3b33190189084158\RobloxPlayerLauncher.exe" -app
start "" "C:\Program Files (x86)\Roblox\Versions\version-3b33190189084158\RobloxPlayerLauncher.exe" -app
i try to search on the internet give nothing more =(
I hope you found the help you needed by now, sad no one responded after all this time. This is not as elegant, but I had the same issue and I did this as my solution:
cd\Progra~2\Roblox\Versions\version-* <-just need a "*" wildcard there
start RobloxPlayerLauncher.exe -app
Hope this helps others that want to run a batch file for programs like Discord and Roblox etc. as their directory names always change with updates.... The practice is annoying and I wish devs would consider end users setups.
rEd2k's answer is fine for use directly on the command line. With a batch script, you can automate it.
Search for the exact folder name with a for /d loop and use the found folder as working folder with the start command:
for /d %%a in ("C:\Program Files (x86)\Roblox\Versions\version-*") do set "rootdir=%%a"
start /d "%rootdir%" RobloxPlayerLauncher.exe -app
NOTE: if there is more than one matching folder (versions), rootdir will contain the last found folder (by string sorting on NTFS), which is probably good enough.

Running ant commands using batch file

Currently this is how I have written the code in the batch file:
C:\ cd C:\abc\xyz\build-scripts-master
call setEnv.cmd
cmd ant do-clean
cmd ant do-dist
This is not working. It just executes the setEnv and breaks out. It does not run the remaining commands
Manually this is how it works:
I first go to the folder C:\abc\xyz\build-scripts-master through the Command Prompt
Then I type in setEnv, which is a windows command script, and hit return.
Then I type in ant do-clean
And then ant do-dist
I want to automate this process and hence was trying to achieve this using batch file.
Try the following:
#CD /D "C:\abc\xyz\build-scripts-master"
#Call setEnv.cmd
#Call ant.bat do-clean
#Call ant.bat do-dist
The latter two lines assume that ant.bat is located somewhere in the current working directory or %PATH%
It is not imperative that the directory path is doublequoted in this case, just good practice.You could continue not to use the .bat extension with ant. I've included it just to make it clear that it is a batch file, and should be Called in the same way as the setEnv batch file.
it didn't run the bat files because you didn't specify the files' location in the code. As it stands right now, the script expects the .bats to exist in the working directory or it has been placed in the folder. The only way it will run the files arbitrarily is if you had placed your working location in the system variables or set the Path to the folders location. I don't know if the cmd and call are needed. I have never used them in my scripts.

Why does my IrfanView command not work on batch file but work when typing directly in CMD?

I'm a first-day user of IrfanView and have a question. I have a bunch of multi-page tiff files and I want to split all of them individually. So I write a batch file with the command like this:
C:\Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif)
C:\Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename2.tif /extract=(D:\newdirectory,tif)
...and so on...
I put the batch file on D drive, let's say in folder "batchfolder". But it can't do the job, this message shows up for each unsuccessful case (all of them were unsuccessful):
D:\batchfolder>C:\Program Files\IrfanView D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif) 1>i_view64.exe
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
I guess that has something to do with the batch file location, so I bring it to C drive. But still it can't run properly, this time a different message shows up:
C:\>C:\Program Files\IrfanView D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif) 1>i_view64.exe
Access is denied.
This C:\>C:\ makes me think maybe the C:\ part on the batch file was redundant. So I take it out to make it look like this:
Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif)
...
But it doesn't work, either with the batch file on D or C drive.
I then try to type it directly in the CMD window and it works normally, like this:
C:\Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif)
Can you tell where my batch file goes wrong?
This is another question. Typing (or copy and paste) the batch file contents into the CMD works OK. But upon successful splitting, the original, multi-image file automatically opens. How can I deactivate this feature?
Note: Cross-post here: https://irfanview-forum.de/showthread.php?t=11150&p=47111#post47111. Hope it doesn't violate policy.
enclose paths/filenames with spaces into quotes to tell the interpreter, it's not two words, but one string (or even better: get used to always enclose path/filenames):
"C:\Program Files\IrfanView\i_view64.exe" "D:\originaldirectory\filename1.tif" /extract=("D:\newdirectory",tif)`
Before you build a batchfile with dozends or hundreds of nearly identical lines, use a for loop to process all .tif files in the folder:
#echo off
for %%a in ("D:\originaldirectory\*.tif") do (
"C:\Program Files\IrfanView\i_view64.exe" "%%~fa" /extract=("D:\newdirectory",tif)
)
see for /? for more information.
You need to call the executable with quotes in the batch. Also, the > in the path will not work either. Also consider using a for loop instead of creating single batch lines.
Please try this:
"C:\Program Files\IrfanView\i_view64.exe" "D:\originaldirectory\filename1.tif" /extract=("D:\newdirectory",tif)

Batch How to start a program

I want to create a batch file to launch my executable file after it has made some changes to itself.
My batch file is:
START /D "C:\Users\me\AppData\Roaming\Test\Test.exe"
When I run it though I just get a brief console flash and Test.exe doesn't start up.
I've verified the EXE is there in the directory.
I've launched the exe manually to verify it is working as well.
My batch file resides in
C:\Users\admin\AppData\Roaming\run.bat"
There are two issues:
The /D option solely defines the starting or working directory, but not the program to execute.
The start command considers the first quoted argument as the title of the new window. To avoid confusion with other arguments, always provide a window title (that may also be empty).
There are two solutions, which are actually not exactly equivalent:
Remove the /D option, so the current working directory is used:
start "" "C:\Users\me\AppData\Roaming\Test\Test.exe"
Keep the /D option and explicitly provide the new working directory to be used:
start "" /D "C:\Users\me\AppData\Roaming\Test" "Test.exe"
try changing to this
start /d "C:\Users\me\AppData\Roaming\Test" Test.exe
You will see the console flash and your program should startup.
Update
Thanks for #SomethingDark 's suggestion to use the following code.
start "" C:\Users\me\AppData\Roaming\Test\Test.exe
However, the above code will not work if your filename contains space.
Try with the following command.Add it to your batch script.Notice that you have to add double quotes after start keyword if there is/are whitespaces in the path string.
start "" "C:\Users\me\AppData\Roaming\Test\Test.exe"
Enclose any directory names which are longer than one-word into quotation marks. So the following path:
start C:\Program Files\MySQL\MySQL Workbench 8.0 CE\MySQL.exe
Should become something like this:
start C:\"Program Files"\MySQL\"MySQL Workbench 8.0 CE"\MySQL.exe

Batch : Renaming a folder in 'program files'

I need to write a batch to rename a folder in Program Files.
I'm able to do it through the Explorer, so I guess I have all required rights.
But when I write something like this in a command line :
move "C:\Program Files\Ceebot4\train" train_old
I get the following error : Access denied.
Is it possible to do it ?
A batch file runs in MS-Dos mode and so is subject to different access rights to Windows Explorer. Try running your batch file or Dos prompt as an administrator should work
You are trying to move the contents to a directory named train_old right under the directory where you currently are when executing the command. If you want to rename the directory in current place you will have to use:
move "C:\Program Files\Ceebot4\train" "C:\Program Files\Ceebot4\train_old"
move moves things, so either do what Anders said (giving the full path in both places; but be careful the target name doesn't already exist), or use ren instead:
ren "C:\Program Files\Ceebot4\train" train_old

Resources