使用WMI,我如何确定远程进程是32位还是64位?
WMI没有此功能。解决方案是通过P/Invoke使用IsWow64Process
测试每个进程的Handle
。 This code应该可以帮助你明白。
谢谢。我会给它一个去。很奇怪他们没有办法在流程类中或者在.NET API中识别这个问题。 – musaul 2011-03-10 13:51:06
试试这个:
/// <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
}
请记住,这个过程是准确的,但在队列中有足够的进程时往往会有点沉重。我在另一个线程中调用了每个进程来缓解UI。 – Xcalibur37 2011-12-09 21:03:51
您正在使用C#编写此代码。 EXE可以在32位或64位模式下运行的语言。你不能从EXE头文件中知道。 – 2011-12-09 22:08:18
您可以编译到特定平台。否则,为什么有2个不同版本的相同的可执行文件? – Xcalibur37 2011-12-10 00:08:21
您使用什么语言? – Helen 2011-03-03 15:14:43
我正在使用C#使用.NET 3.5 – musaul 2011-03-03 16:13:25
相关:[如何确定System.Diagnostics.Process是32位还是64位?](http://*.com/q/3575785/113116) – Helen 2011-03-09 19:13:34