python';s ctypes c_char是否适用于windows 64?

python';s ctypes c_char是否适用于windows 64?,python,ctypes,Python,Ctypes,我试图加载一个进程列表,它在32位python上正常工作。但是,在64位上,我无法获得要列出的进程名称。代码如下。如果我将szExeFile的结构从c_char更改为c_int或long,进程列表将枚举,但我无法看到pid属于哪个exe。如何使其在x64上运行 from ctypes import * from ctypes.wintypes import * import sys # const variable # Establish rights and basic options n

我试图加载一个进程列表,它在32位python上正常工作。但是,在64位上,我无法获得要列出的进程名称。代码如下。如果我将szExeFile的结构从c_char更改为c_int或long,进程列表将枚举,但我无法看到pid属于哪个exe。如何使其在x64上运行

from ctypes import *
from ctypes.wintypes import *
import sys


# const variable
# Establish rights and basic options needed for all process declartion / iteration
TH32CS_SNAPPROCESS = 2
STANDARD_RIGHTS_REQUIRED = 0x000F0000
SYNCHRONIZE = 0x00100000
PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF)
TH32CS_SNAPMODULE = 0x00000008
TH32CS_SNAPTHREAD = 0x00000004

##  Create object definitions to story information in
class PROCESSENTRY32(Structure):
    _fields_ = [ ( 'dwSize' , c_uint ) , 
                 ( 'cntUsage' , c_uint) ,
                 ( 'th32ProcessID' , c_uint) ,
                 ( 'th32DefaultHeapID' , c_uint) ,
                 ( 'th32ModuleID' , c_uint) ,
                 ( 'cntThreads' , c_uint) ,
                 ( 'th32ParentProcessID' , c_uint) ,
                 ( 'pcPriClassBase' , c_long) ,
                 ( 'dwFlags' , c_uint) ,
                 ( 'szExeFile' , c_char * 260 ) ]

CreateToolhelp32Snapshot= windll.kernel32.CreateToolhelp32Snapshot
Process32First = windll.kernel32.Process32First
Process32Next = windll.kernel32.Process32Next
GetLastError = windll.kernel32.GetLastError
OpenProcess = windll.kernel32.OpenProcess
GetPriorityClass = windll.kernel32.GetPriorityClass
CloseHandle = windll.kernel32.CloseHandle

try:
    hProcessSnap = c_void_p(0)
    hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS , 0 )
    pe32 = PROCESSENTRY32()
    pe32.dwSize = sizeof( PROCESSENTRY32 )
    ret = Process32First( hProcessSnap , pointer( pe32 ) )
    global PROGPid
    PROGPid=False
    while ret:
        print pe32.dwSize,pe32.cntUsage,pe32.th32ProcessID,pe32.th32DefaultHeapID,pe32.th32ModuleID,pe32.cntThreads,pe32.th32ParentProcessID,pe32.pcPriClassBase,pe32.dwFlags,pe32.szExeFile
        hProcess = OpenProcess( PROCESS_ALL_ACCESS , 0 , pe32.th32ProcessID )
        dwPriorityClass = GetPriorityClass( hProcess )
        if dwPriorityClass == 0 :
            CloseHandle( hProcess )
        PROGPid=pe32.th32ProcessID
        ret = Process32Next( hProcessSnap, pointer(pe32) )
        print PROGPid
    CloseHandle ( hProcessSnap )

except:
    print "Error in ListProcessPid"
你的观点是错误的。这对我很有用:

class PROCESSENTRY32(Structure):
    _fields_ = [ ( 'dwSize' , DWORD ) ,
                 ( 'cntUsage' , DWORD) ,
                 ( 'th32ProcessID' , DWORD) ,
                 ( 'th32DefaultHeapID' , POINTER(ULONG)) ,
                 ( 'th32ModuleID' , DWORD) ,
                 ( 'cntThreads' , DWORD) ,
                 ( 'th32ParentProcessID' , DWORD) ,
                 ( 'pcPriClassBase' , LONG) ,
                 ( 'dwFlags' , DWORD) ,
                 ( 'szExeFile' , c_char * 260 ) ]

创建一个进程列表
psutil
目前通过使用单个代码库支持Linux、Windows、OSX和FreeBSD,包括32位和64位,Python版本从2.4到3.3。Pypy也可以工作。此环境中的发行版没有PSUTIL,我无法部署它。它可以在x64上工作吗?它可以,wmi索引也可以。使用kernel32 vs.paspi的原因是为了找到程序dll的基本内存偏移量。Char也用于“firstmodule”/“lastmodule”函数,并产生相同的问题。您能告诉我您是从哪里/如何提出这种结构的吗?我试图对MODULEENTRY32做同样的事情,但遇到了类似的问题。这些结构在MSDN中有记录,例如,是的,我使用了其中列出的结构,但出现了故障。你能看一看吗