It seems that Win32::API::Struct::Sizeof is returning the wrong size. Setting it to 296 and your code works:
#! perl -slw use strict; use Data::Dumper; use Win32::API; Win32::API::Struct->typedef( PROCESSENTRY32 => qw{ LONG dwSize; LONG cntUsage; LONG th32ProcessID; LONG th32DefaultHeapID; LONG th32ModuleID; LONG cntThreads; LONG th32ParentProcessID; LONG pcPriClassBase; LONG dwFlags; CHAR szExeFile[260]; }) ; Win32::API->Import('kernel32.dll', "HANDLE CreateToolhelp32Snapshot(DW +ORD dwFlags,DWORD th32ProcessID)"); Win32::API->Import('kernel32.dll', "BOOL Process32First( HANDLE hSnaps +hot, LPPROCESSENTRY32 lppe )" ); Win32::API->Import('kernel32.dll', "BOOL Process32Next( HANDLE hSnapsh +ot, LPPROCESSENTRY32 lppe )" ); my $TH32CS_SNAPPROCESS = 0x2; $^W=0; my $Snapshot = undef; my $ProcessInfo = Win32::API::Struct->new('PROCESSENTRY32') or die $^E +; $Snapshot = CreateToolhelp32Snapshot($TH32CS_SNAPPROCESS, 0) or die $^ +E; $ProcessInfo->{dwSize} = 296; #Win32::API::Struct::sizeof ($ProcessInf +o); my $Sucess = Process32First( $Snapshot, $ProcessInfo) or die $^E; print "First Process : $ProcessInfo->{szExeFile}\n"; #are returning no +thing #print Dumper $ProcessInfo; while( Process32Next( $Snapshot, $ProcessInfo ) ) { print $ProcessInfo->{szExeFile}; # print Dumper $ProcessInfo; } __END__ P:\test>446283 First Process : [System Process] System SMSS.EXE CSRSS.EXE WINLOGON.EXE SERVICES.EXE LSASS.EXE SVCHOST.EXE SVCHOST.EXE SVCHOST.EXE SVCHOST.EXE vsmon.exe EXPLORER.EXE zlclient.exe TASKMGR.EXE mdm.exe CMD.EXE CMD.EXE CMD.EXE CMD.EXE CMD.EXE CMD.EXE opera.exe perl.exe
I worked out what was wrong by adding some error checking which produced the error text: "The program issued a command but the command length is incorrect" from the call to Process32First().
In reply to Re: Win32::API Help !
by BrowserUk
in thread Win32::API Help !
by shonorio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |