简体   繁体   English

使用WMI,如何确定远程进程是32位还是64位?

[英]Using WMI, how can I determine whether a remote process is 32-bit or 64-bit?

I have a collection of win32_process objects queried from a remote machine using WMI. 我有一个使用WMI从远程计算机查询的win32_process对象的集合。 How do I determine whether each process is 32-bit or 64-bit? 如何确定每个进程是32位还是64位?

WMI doesn't have this functionality. WMI没有此功能。 The solution is to test each process's Handle using IsWow64Process via P/Invoke. 解决方案是通过P / Invoke使用IsWow64Process测试每个进程的Handle This code should help you get the idea. 这段代码应该可以帮助您实现这个想法。

Try this: 尝试这个:

/// <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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM