2

I have a few programs I am currently working with, such as WinRAR, that have both the 32 and 64-bit versions. I want to make a script (VB or Batch) at the root of the project folder that can "scan" for the proper program to use in accordance with the local machines processor architecture.

Could this be done either with a simple file name trick using variables such as WinRAR x86.exe and WinRAR x64.exe or use the internal program architecture if renaming the binaries in a given scenario isn't an option?

I have downloaded programs such as Cheat Engine, that have both 32 and 64 bit versions that also include a binary that can do this.

Can this be done with simple script programing, and if so, how and with what script format should I use?

  • "Could this be done either with a simple file name trick" - Possibly but not always. – Ramhound Jul 2 '17 at 2:37
  • 1
  • Dude you are smart, and apparently, willing to learn. In all honesty I suggest you move on to a better scripting language - Python (easily cross platform) and if you wanna specialize on windows, use powershell (even the parent company's seriously dedicated towards making it mainstream) instead of batch script – RinkyPinku Jul 3 '17 at 13:13
  • I plan on learning other programming languages such as Python, C, C++, C#, and so on. I just don't have the time for that currently. More recently I've been learning Visual Basic (hence why I suggested the option), it seems to be more advanced than batch, and will likely take me longer to learn. – Mr. Mendelli Jul 3 '17 at 17:19
  • Okay, if your project isn't a top secret, tell me about it. I'll try to implement it and give you the code with explanation. Just so that you know how fast easy development in Python is. And C, C++ are not scripting languages. – RinkyPinku Jul 4 '17 at 12:21
6

Use batch script or vb script to store output of wmic os get osarchitecture and you get a string value saying 32-bit or 64-bit. Then you can use the typical conditional if-then-else to launch the appropriate binary. Problem solved.

Alternative method:

The %PROCESSOR_ARCHITECTURE% environment variable stores this information , to understand the possible values it returns, refer this blog post- https://blogs.msdn.microsoft.com/david.wang/2006/03/27/howto-detect-process-bitness/


P.S. don't depend on accessing OS drive (remember, it's not always C:) looking for Program Files (x86) or other hacks like that, you might run into permission issues and it's not the standard way of doing this.

  • +1 for it's not always C: – RinkyPinku Jul 2 '17 at 4:05
  • I'm actually going to put both versions of a given program in one folder with the script at the root next to the folders. I'm doing this for the best results and portability. This way the script only needs to search forwards once. – Mr. Mendelli Jul 2 '17 at 5:18
  • Nice approach but then you need to manually rename each file (indicating their versions) and hardcode them in your script. Better to keep 2 folders 64-bit and 32-bit in each program's folder. This approach is semantic, easier to write and more scalable :) – RinkyPinku Jul 2 '17 at 10:04
  • Thank uou for your information, but I'm still relatively new to programming. I can't find a way to incorporate the %PROCESSOR_ARCITECTURE% variable into my script. Usually when I make a batch script that runs another program, I place it as far back as desired, then I place the path to the executable or target wraped in quotation marks starting with ".\". Other times I use arguments (if posdible) after declaring the target path. Would you be so kind as to provide an example, assuming the two possible paths are "%X86PROG%\%X86PROG%.exe" and "%X64PROG%\%X64PROG%.exe%"? – Mr. Mendelli Jul 2 '17 at 10:44
  • 1
    @Mr.Mendelli - echo %processor_architecture%%processor_architew6432% | findstr 64 >nul && set "prog=%x64prog%\%x64prog%.exe" || set "prog=%x86prog%\%x86prog%.exe" – dbenham Jul 2 '17 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.