procedure RefreshList; //刷新进程列表
var
h:THandle;
procEntry32:TProcessEntry32;
isEnd:Bool;
s:ShortString;
begin
list1.clear;
h:=createToolhelp32snapshot(TH32CS_SNAPPROCESS,0);
procEntry32.dwSize:=sizeof(TProcessEntry32);
isEnd:=Process32First(h,procEntry32);
while isEnd do
begin
GetModuleFileName(openProcess(Process_All_Access,
true,procEntry32.th32ProcessID),@s,255);
list1.Items.Add(s);
isEnd:=Process32Next(h,procEntry32);
end;
CloseHandle(h);
end;
//为什么list1中什么也没有(list1是一个listbox)
true,procEntry32.th32ProcessID),@s[1],255);
Delphi自带了个例程啊.!
true,procEntry32.th32ProcessID),pchar(s),255);
你这样写当然取不到了。其实一个参数应该是GetModuleHandle的返回值,不过这个函数的参数又恰是你想得到了。
别用procEntry32.th32ModuleID,它应该一直是0,是该进程自己模块的handle,所以是0。
若你用0取会得到自己程序整个路径。
在9x下procEntry32.szExeFile是完整路径名称,不过2000下只是名称。
我想你可以用Module32First,Module32Next去遍历模块,只取第一个模块的szExePath就可以了。
不知道还有没有其他合适的办法,因为用ModuleXXX还得遍历Process。