5

我有一个使用 WMI 从远程计算机查询的 win32_process 对象集合。如何确定每个进程是 32 位还是 64 位?

4

2 回答 2

1

WMI 没有此功能。解决方案是通过 P/Invoke测试每个进程的Handle使用情况。这段代码应该可以帮助您了解这个想法。IsWow64Process

于 2011-03-09T19:13:11.130 回答
0

尝试这个:

/// <summary>
/// Retrieves the platform information from the process architecture.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string GetPlatform(string path)
{
    string result = "";
    try
    {
        const int pePointerOffset = 60;
        const int machineOffset = 4;
        var data = new byte[4096];
        using (Stream s = new FileStream(path, FileMode.Open, FileAccess.Read))
        {
            s.Read(data, 0, 4096);
        }
        // Dos header is 64 bytes, last element, long (4 bytes) is the address of 
        // the PE header
        int peHeaderAddr = BitConverter.ToInt32(data, pePointerOffset);
        int machineUint = BitConverter.ToUInt16(data, peHeaderAddr +
                                                      machineOffset);
        result = ((MachineType) machineUint).ToString();
    }
    catch { }

    return result;
}



public enum MachineType
{
    Native = 0,
    X86 = 0x014c,
    Amd64 = 0x0200,
    X64 = 0x8664
}
于 2011-12-09T21:01:27.967 回答