0

How can I create a batch file that tells if an installed program (.exe) is 32 or 64 bit?

Sometimes you can tell based on the which folder the program.exe file is in.

If the installed program is 32 bit it will show up in the Program Files (x86)folder. If the file is 64 bit it will show up in the Program Files folder.

But this is not always the case...

For example Google Chrome always shows up in Program Files x86

Chrome in Program Files x86

But the version on my computer is 64 bit:

Chrome is actually 64 bit

How can I reference chrome.exe for example and have batch tell me if its 64 or 32 bit?

  • Possible duplicate of [batch file to check 64bit or 32bit OS](https://stackoverflow.com/questions/12322308/batch-file-to-check-64bit-or-32bit-os) – Mister SirCode Mar 28 '19 at 14:44
  • Taylor that post explains how to tell if the Operating System is 32 or 64 bit. I would like to know if the installed programs are 32 or 64 bit. Please remove what you just did –  Mar 28 '19 at 14:46
  • @TaylorSpark do you have any suggestions? –  Mar 28 '19 at 14:53
  • cross-site duplicates: [How to check if a binary is 32 or 64 bit on Windows?](https://superuser.com/q/358434/241386), [Check if exe is 64-bit](https://reverseengineering.stackexchange.com/q/6040/2563). It's very difficult to deal with this in batch, but you can call powershell or another 3rd party tool from batch – phuclv Mar 28 '19 at 15:14
  • Possible duplicate of [How do I determine whether an application I am installing is 32-bit or 64-bit?](https://stackoverflow.com/questions/1858358/how-do-i-determine-whether-an-application-i-am-installing-is-32-bit-or-64-bit) – phuclv Mar 28 '19 at 15:17
  • @phuclv Know one seems to be able to explain how to do this simply with Powershell with no external programs. –  Mar 28 '19 at 16:54

1 Answers1

0

This script will do the trick: Identify 16-bit, 32-bit and 64-bit executables with PowerShell

If you call this from within powershell: "Source" (aka) run the script once to get the function into memory then you can just use it..

    . .\Get-ExecutableType.ps1 #sources the script
    Get-ExecutableType -Path C:\Windows\System32\notepad.exe #runs the function

To call this script "the easy way" from a batch file, add this to the bottom of the script after the last curly brace:

    Get-ExecutableType -Path $args[0]

And call it like this:

powershell -command "& .\Get-ExecutableType.ps1 X:\Your.exe"

Other options:

You can also use the added "batch lines" to call it from powershell without sourcing the file first.

You can also use silly powershell syntax to call the function without sourcing the file first. powershell.exe -c "& { [script_file] [params] ; [function_name] }"

Señor CMasMas
  • 4,290
  • 2
  • 14
  • 21
  • I am having trouble understand how to run the script. When opening the script in powershell it executes the functions and then goes back to an empty prompt –  Mar 28 '19 at 17:50
  • Thank you, can you please take a look at my newest question: https://stackoverflow.com/questions/55404578/how-to-use-output-from-sigcheck-to-make-conditional-statment-using-batch –  Mar 28 '19 at 18:47
  • I am looking into a few alternative ways, and I need some help finishing this other one –  Mar 28 '19 at 18:48