0

I am able to create a batch file to run an application like this:

@ECHO OFF
START "" "C:\Program Files (x86)\Folder\myapp.exe" 

But since the OS of the client's workstation is 32-bit OS (mine is 64-bit OS), how can I write a command that I can run on my workstation and the client as well?

Mofi
  • 46,139
  • 17
  • 80
  • 143
YWah
  • 571
  • 13
  • 38

3 Answers3

1
:CheckOS
IF EXIST "%PROGRAMFILES(X86)%" (GOTO 64BIT) ELSE (GOTO 32BIT)

:64BIT
START "" "C:\Program Files (x86)\Folder\myapp.exe" 
GOTO END

:32BIT
START "" "C:\Program Files\Folder\myapp.exe" 
GOTO END

:END

Refer: batch file to check 64bit or 32bit OS

Community
  • 1
  • 1
Sunil Lama
  • 4,531
  • 1
  • 18
  • 46
  • What if the Windows is **not** installed on `C:`? – axiac Feb 21 '16 at 20:01
  • i don't think you understood what i wrote, it checks your os whether it is on c: or D: then it goes for 64 bit or 32 bit. After that it is starting the program that is in C:\ . So, if your windows is not installed on C: your filepath would simply had been C:\yourfolder\yourapp.exe. – Sunil Lama Feb 22 '16 at 02:38
  • 1
    The `Program Files` directories are located on the same drive as the `Windows` directory (not necessarily on `C:`). Even more, the localized versions of Windows use localized names for this directory. (I don't know for the Windows 7 and newer but this is how it used to work on Windows XP and previous versions.) The test using `%PROGRAMFILES(X86)%` is the correct way to do it but also use the environment variables to create the path of the application to start. – axiac Feb 22 '16 at 07:52
  • what if `%PROGRAMFILES(X86)%` is not `C:\Program Files (x86)`? – phuclv Mar 02 '16 at 08:32
0

I suggest to use a batch code which really searches first for the application to start before starting it.

@echo off
rem The program files folder exists on all Windows.
for /R "%ProgramFiles%" %%I in (myapp*.exe) do (
    start "" "%%I"
    goto :EOF
)

rem The x86 program files folder exists only on all Windows x64.
if not "%ProgramFiles(x86)%" == "" (
    for /R "%ProgramFiles(x86)%" %%I in (myapp*.exe) do (
        start "" "%%I"
        goto :EOF
    )
)

echo Can't find myapp.exe in any program files folder.
echo.
pause

But if the application is installed with adding its executable name as key to

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths

or to

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths

the command start would find the application to start by itself on specifying just myapp.exe. See the answers on Where is “START” searching for executables? and How to enumerate all programs that can open XML file as plain text? for more details.

Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143
-1

Try checking to see if the directory exists, like this:

@ECHO OFF
IF EXIST "%PROGRAMFILES(X86)%" (
    START "" "C:\Program Files (x86)\Folder\myapp.exe" 
) ELSE (
    START "" "C:\Program Files\Folder\myapp.exe" 
)