Zai*_*zvi 5 powershell powershell-3.0
有没有办法确定给定的进程ID是针对32位还是64位进程?我正在使用Powershell v3.0
试试这个:
Add-Type -MemberDefinition @'
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process(
[In] System.IntPtr hProcess,
[Out, MarshalAs(UnmanagedType.Bool)] out bool wow64Process);
'@ -Name NativeMethods -Namespace Kernel32
Get-Process -Id $id | Foreach {
$is32Bit=[int]0
if ([Kernel32.NativeMethods]::IsWow64Process($_.Handle, [ref]$is32Bit)) {
"$($_.Name) $($_.Id) is $(if ($is32Bit) {'32-bit'} else {'64-bit'})"
}
else {"IsWow64Process call failed"}
}
Run Code Online (Sandbox Code Playgroud)
这里应该检查以确保操作系统是64位,否则所有进程都是32位.