2011-03-03 86 views
5

我有一個使用WMI從遠程機器查詢win32_process對象的集合。我如何確定每個進程是32位還是64位?使用WMI,我如何確定遠程進程是32位還是64位?

+0

您使用什麼語言? – Helen 2011-03-03 15:14:43

+0

我正在使用C#使用.NET 3.5 – musaul 2011-03-03 16:13:25

+2

相關:[如何確定System.Diagnostics.Process是32位還是64位?](http://stackoverflow.com/q/3575785/113116) – Helen 2011-03-09 19:13:34

回答

1

WMI沒有此功能。解決方案是通過P/Invoke使用IsWow64Process測試每個進程的HandleThis code應該可以幫助你明白。

+0

謝謝。我會給它一個去。很奇怪他們沒有辦法在流程類中或者在.NET API中識別這個問題。 – musaul 2011-03-10 13:51:06

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 
} 
+0

請記住,這個過程是準確的,但在隊列中有足夠的進程時往往會有點沉重。我在另一個線程中調用了每個進程來緩解UI。 – Xcalibur37 2011-12-09 21:03:51

+0

您正在使用C#編寫此代碼。 EXE可以在32位或64位模式下運行的語言。你不能從EXE頭文件中知道。 – 2011-12-09 22:08:18

+0

您可以編譯到特定平臺。否則,爲什麼有2個不同版本的相同的可執行文件? – Xcalibur37 2011-12-10 00:08:21

相關問題