How to check the location of the 32-bit Program Files folder in .bat script windows

I want to write a .bat script that works in all Windows styles, regardless of 32 or 64 bit.

In this script, I want to run file.exe. This file is located in C: \ Program Files \ under 32-bit systems or C: \ Program FIles (x86) \ under x64. I can write:

"% ProgramFiles (x86)% \ file.exe" on 64-bit systems or "% ProgramFiles% \ file.exe" on 32-bit systems but I want to make a universal script. Is there a way to define this path universally?

+4
source share
5 answers

You can simply verify its existence and save the path;

@echo off & setLocal enabledelayedexpansion if exist "C:\Program Files\app1.exe" ( set PPATH="C:\Program Files\" ) else ( set PPATH="C:\Program Files(x86)\" ) start "" %PPATH%app1.exe start "" %PPATH%app2.exe start "" %PPATH%app3.exe 
+6
source

VBS script:

  set wshShell = createObject("WScript.Shell") ''----------------------------------- ''Get 32-bit program files path ''----------------- OsType = wshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE") If OsType = "x86" then '''wscript.echo "Windows 32bit system detected" strProgramFiles = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%") elseif OsType = "AMD64" then '''wscript.echo "Windows 64bit system detected" strProgramFiles = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%") end if 
+4
source

"whereis" is the linux command for this, but the Windows port is available (I think it is unxutils). You will not get the way without it.

+1
source

I think you should use a VBScript / JScript file instead of the "bat" file. Any of these scripts can be executed using the Windows Script interpreter (wscript.exe / cscript.exe). Script and interpreters are available in all window options, so there is nothing to worry about. You can find code samples for moving directory structures, checking for file availability, etc. Using VBScript. You can use FileSystemObject Object for the most part.

+1
source

For simplicity, you can always do the following:

 cd %PROGRAMFILES% cd %PROGRAMFILES(x86)% Program.exe 

This suggests that you don’t need to complicate anything, but if installing the current directory is enough, this should work fine.

+1
source

Source: https://habr.com/ru/post/1310217/


All Articles