用于检查安装的程序是 64 位还是 32 位的批处理文件?

Batch file to check if installed program is 64 bit or 32 bit?

如何创建批处理文件来判断安装的程序 (.exe) 是 32 位还是 64 位?

有时您可以根据 program.exe 文件所在的文件夹来判断。

如果安装的程序是 32 位的,它将显示在 Program Files (x86) 文件夹中。如果文件是 64 位,它将显示在 Program Files 文件夹中。

但情况并非总是如此...

例如 Google Chrome 总是出现在 Program Files x86

Chrome in Program Files x86

但是我电脑上的版本是64位的:

Chrome is actually 64 bit

我如何引用 chrome.exe 示例并让批处理告诉我它是 64 位还是 32 位?

这个脚本可以解决问题: Identify 16-bit, 32-bit and 64-bit executables with PowerShell

如果您从 powershell 中调用此 : "Source"(又名)运行 脚本一次将函数存入内存,然后您就可以使用它了..

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

要从批处理文件调用此脚本"the easy way",请将其添加到脚本底部最后一个花括号后:

    Get-ExecutableType -Path $args[0]

并这样称呼它:

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

其他选项:

您还可以使用添加的 "batch lines" 从 powershell 调用它,而无需先获取文件。

您也可以使用愚蠢的 powershell 语法来调用函数,而无需先获取文件。 powershell.exe -c "& { [script_file] [参数] ; [function_name] }"