36

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.

ouflak
  • 2,458
  • 10
  • 44
  • 49
explorer
  • 1,074
  • 2
  • 11
  • 31
  • I have tried Googling before posting. I have used terms like "how can we mention Program Files directory in batch file?" but couldn't get proper results.Thanks – explorer Oct 29 '13 at 09:07
  • 2
    Try searching for `cmd.exe how to specify a path with spaces`. – Bill_Stewart Apr 23 '15 at 16:42

8 Answers8

61

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"
Rémi Benoit
  • 1,307
  • 11
  • 17
  • 17
    better to use environment variables `"%ProgramFiles%"` and `"%ProgramFiles(x86)%"` – npocmaka Oct 29 '13 at 08:05
  • @DavidCandy Indeed, fixed. – Rémi Benoit Oct 29 '13 at 08:41
  • 2
    Wow, never knew that `^` is an escape character in Windows. I've always thought that it's just ctrl+key. BTW in win 64 bit there's another environment variable to access 32-bit program files: `%ProgramW6432%` – phuclv Oct 29 '13 at 08:53
  • C:\Program^ Files is the one which I was looking for. Thanks a lot! – explorer Oct 29 '13 at 09:11
  • @RameshJothimani If this answers the question please mark the answer as accepted using the green tick. – Rémi Benoit Oct 29 '13 at 09:19
  • @RémiBenoit : Sure.I have just got one more issue.When I use it in my actual batch file as "start C:\Program^ Files\temp.exe" , I am getting error but it works fine when I use "E:\Program^ Files\temp.exe".Kindly suggest some solution. – explorer Oct 29 '13 at 13:43
  • Maybe `temp.exe` is located in the E: drive? – Rémi Benoit Oct 30 '13 at 04:01
  • @RémiBenoit : The file exists in "C:\Program^ Files\temp.exe" I have metioned it as E:\ drive by mistake.Since there is a command Start before "C:\Program^ Files\temp.exe" , I am getting error.Kindly suggest some solution. – explorer Oct 30 '13 at 06:06
  • Ha, I didn't see the `start` function. What is the point of this function? If you just need to run `temp.exe` remove it. – Rémi Benoit Oct 30 '13 at 06:18
  • @RameshJothimani: Instead of using escape characters, adding `"` around the path is more readable and is "standard" in passing paths in Windows. I've never seen a program using `^` to escape – phuclv Oct 30 '13 at 06:43
  • 1
    If you need to specify many parameters before running the program such as priority, affinity... then call it with `start`. Otherwise, just use the filename, that's enough – phuclv Oct 30 '13 at 06:45
  • Note that `start` is not directly interchangeable with using the filename: `start` without `wait` runs the program asynchronously with the rest of the batch file (instead of pausing until the program finishes); and if the exe cannot be found, `start` stops the batch file with a popup message. – Luis Oct 19 '15 at 17:01
  • @RameshJothimani, I would never recommend escaping special characters in paths. The accepted best practice is to use quotes around file paths with spaces and special characters. – Squashman Mar 11 '17 at 14:13
8

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
Chris G
  • 787
  • 6
  • 20
user5861369
  • 81
  • 1
  • 1
2

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.

antoni
  • 5,001
  • 1
  • 35
  • 44
2

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

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
RaZa74
  • 21
  • 1
  • 1
    And do you know why it works? How does this solve OPs problem? – Yunnosch Mar 14 '20 at 11:20
  • It's much better to ask to run `dir /X c:\` once to get the shortened name, which indeed can work. But may also be ~1, or in theory any other number... – B. Go Mar 14 '20 at 11:49
  • @RaZa74 It is a good practice to align your answers to what OP asks. Your answer would definitely have got some upvotes if you framed it correctly. Just saying ... – Prakhar Mar 14 '20 at 11:49
1

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

Christian Sirolli
  • 246
  • 1
  • 6
  • 18
0

use this as somethink

"C:/Program Files (x86)/Nox/bin/nox_adb" install -r app.apk

where

"path_to_executable" commands_argument
0

Interestingly with variables ,this worked for me ...

SET "VESTADIR=\\%TARGET%\C$\"Program Files (x86)"\Cassidian\VESTA"
Mike Q
  • 6,716
  • 5
  • 55
  • 62
-4

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.

iNoob
  • 3,364
  • 2
  • 26
  • 33