3

I want to make a batch or command script that can find the proper program to use in accordance with the local machines processor architecture for 32-bit and 64-bit programs.

One program I would like to try this with is WinRAR. I want to place the 64-bit version in a folder called "x64" and the 32-bit in a folder labeled "x86" with the script besides these folders.

I have noticed that some programs such as Cheat Engine, have a 32 and 64 bit version that also include an executable that can do this.

Currently my only lead is the %process_architecture% variable. This was the script I made using @dbenham's original script:

echo %processor_architecture%%processor_architew6432% | findstr 64 >nul && set "prog=x64\WinRAR x64.exe" || set "prog=x86\WinRAR x86.exe"
2
  • 1
    You will faster get answer for this question on stackoverflow.
    – kelin
    Jul 9, 2017 at 8:56
  • 1
    @kelin Not so. It would get closed as too broad on Stack Overflow as the OP has provided no VB code. In any case it can be done in batch. See my answer.
    – DavidPostill
    Jul 9, 2017 at 9:11

2 Answers 2

2

How can I find the proper program to use as per the processor architecture?

This was the script I used:

echo %processor_architecture%%processor_architew6432% | findstr 64 >nul && set "prog=x64\WinRAR x64.exe" || set "prog=x86\WinRAR x86.exe"

Notes:

  • The above code used by the OP was taken from this comment by dbenham.

  • %processor_architew6432% is normally undefined on a 64 bit system (the exception is when a 32-bit process is created by a 64-bit process). See WOW64 Implementation Details for more information.

I normally use wmic OS get OSArchitecture to get the OS bitness.

The following batch file should get you started:

@echo off
setlocal enabledelayedexpansion
for /f "usebackq skip=1 tokens=*" %%i in (`wmic OS get OSArchitecture ^| findstr /r /v "^$"`) do (
  set "_bits=%%i"
  rem remove spaces
  set "_bits=!_bits: =!"
  )
if "%_bits%" EQU "64bits" (
  rem 64bit OS
  set "prog=x64\WinRAR x64.exe"
  ) else (
  rem 32bit OS
  set "prog=x86\WinRAR x86.exe"
  )
rem do something with %prog%
call %prog%
endlocal

Further Reading

10
  • I gave your script a shot, but it does the same thing no matter what variables I use. Jul 9, 2017 at 9:14
  • @Mr.Mendelli What are you doing with %prog% once it has been set?
    – DavidPostill
    Jul 9, 2017 at 9:28
  • @Mr.Mendelli what is "the same thing" that it does? You've not said what doesn't actually work in the script you use.
    – Mokubai
    Jul 9, 2017 at 9:29
  • I changed each one accordingly to %processor_architew6432% and %processor_architecture%. I apologize, I am still figuring out how batch scripting works. Jul 9, 2017 at 9:30
  • 1
    @Mr.Mendelli Setting a variable (like prog) doesn't actually do anything. Try adding call %prog% once it has been set. Answer updated.
    – DavidPostill
    Jul 9, 2017 at 9:33
0

Here's my way of finding out:

if exist %windir%\syswow64 ( set ARCH=x64 ) else ( set ARCH=x86 )

Simple. Works every time

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .