如何在PowerShell中检查要安装的可执行文件是32位还是64位?
在powershell中是否有任何预定义功能可以做到这一点?
有许多用于PowerShell的高级PE标头解析器。
这是一个仅读取“机器类型”字段的简单函数:
function Is64bit([string]$path) {
try {
$stream = [IO.File]::OpenRead($path)
} catch {
throw "Cannot open file $path"
}
$reader = [IO.BinaryReader]$stream
if ($reader.ReadChars(2) -join '' -ne 'MZ') { throw 'Not an executable' }
$stream.position = 0x3C
$stream.position = $reader.ReadUInt32() # go to COFF
if ($reader.ReadUInt32() -ne 0x00004550) { throw 'Not a PE executable' }
return $reader.ReadUInt16() -eq 0x8664 # machine type
}
用法:
Is64bit C:\Windows\explorer.exe
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句