use TLhelp32,
你可以用其他函数得到路径,DELPLHI5开发人员指南上得例子是错得var FSnap:Thandle;
PE:TprocessEntry32;
PPE:PProcessEntry32;
begin
str:='P_';
if FSnap>0 then closeHandle(FSnap);
FSnap:=createtoolhelp32Snapshot(TH32CS_SNAPALL,0);
if FSnap=-1 then
raise Exception.create('Windows发生致命错误即将关闭!');
PE.dwsize:=sizeof(PE);
if Process32first(FSnap,PE) then
repeat
New(PPE);
PPE^:=PE;
NAMEID:=PPE.Th32processID);
NAME:=PPE.szExeFile+'+';
until Not Process32next(FSnap,PE);
closeHandle(FSnap);
end;
你可以用其他函数得到路径,DELPLHI5开发人员指南上得例子是错得var FSnap:Thandle;
PE:TprocessEntry32;
PPE:PProcessEntry32;
begin
str:='P_';
if FSnap>0 then closeHandle(FSnap);
FSnap:=createtoolhelp32Snapshot(TH32CS_SNAPALL,0);
if FSnap=-1 then
raise Exception.create('Windows发生致命错误即将关闭!');
PE.dwsize:=sizeof(PE);
if Process32first(FSnap,PE) then
repeat
New(PPE);
PPE^:=PE;
NAMEID:=PPE.Th32processID);
NAME:=PPE.szExeFile+'+';
until Not Process32next(FSnap,PE);
closeHandle(FSnap);
end;
解决方案 »
- delphi 线程 access violation at address
- 数据库表中的数据输入073,结果只显示73,求助!
- 向表插入记录时出现的问题,具体原因快想破头了,小弟初学EDLPHI,迷茫~~~~
- ADO+Access 日期时间类型字段的问题, 急!!!
- 请教:怎样单独设置stringGrid的某一列为只读。谢谢
- access数据库支持like(模糊查询)方式么?
- 问一个查询的问题,很简单的
- 更新delphi可执行文件后运行提示:"参数不正确"
- 国标软件设计文档--哪里有?请告知
- 怎样获得listview的某行某列的内容
- 关于创建进程与结束进程的问题!
- 紧急求助,SQL高手请进:INSERT INTO FOX表中,生成一个字串,数字字段如何处理:不吝高分!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Tlhelp32, StdCtrls, Buttons, CheckLst;type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
ListBox1: TListBox;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;procedure Search(Strings:TStrings);
implementation{$R *.dfm}
procedure Search(Strings:TStrings);
var
Snap:THandle;
RB:Boolean;
PE:TProcessEntry32;
begin
if Strings=nil then
Exit;
snap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if snap = -1 then Exit;
try
PE.dwSize:=SizeOf(TProcessEntry32);
RB:=Process32First(snap,PE);
while RB do
begin
Strings.Add(PE.szExeFile);
PE.dwSize:=SizeOf(TProcessEntry32);
RB:=Process32Next(snap,PE);
end;
finally
CloseHandle(snap);
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Search(ListBox1.Items);
end;end.
注意要在Uses中加入Tlhelp32单元 再加至少50分,我再教你怎么Kill一个进程!!!!
结束进程可用 TerminateProcess这个API
建议你去买本《Delphi5编程指南》,里面有一个列举系统所有进程得例子
win2000没有,根本就不是上面的方法啦!别来骗分了!
procedure NewProcess(ProcessID: DWORD);
var
I: Integer;
Count: DWORD;
ProcHand: THandle;
ModHandles: array[0..$3FFF - 1] of DWORD;
ModInfo: TModuleInfo;
ModName: array[0..MAX_PATH] of char;
Item: TListItem;
begin
FProcessID:=ProcessID;
ProcHand := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False,
ProcessID);
if ProcHand = 0 then
raise Exception.Create('No information available for this process/driver');
try
EnumProcessModules(ProcHand, @ModHandles, SizeOf(ModHandles), Count);
for I := 0 to (Count div SizeOf(DWORD)) - 1 do
if (GetModuleFileNameEx(ProcHand, ModHandles[I], ModName,
SizeOf(ModName)) > 0) and GetModuleInformation(ProcHand,
ModHandles[I], @ModInfo, SizeOf(ModInfo)) then
with ModInfo do
begin
Item:=lvMoudle.Items.Add;
Item.Caption:=ModName;
Item.SubItems.Add(IntToHex(DWord(lpBaseOfDll),8));
Item.SubItems.Add(IntToHex(DWord(SizeOfImage),8));
Item.SubItems.Add(IntToHex(DWord(EntryPoint),8));
end;
finally
CloseHandle(ProcHand);
end;
end;
运行不了啦!!!!!!! ?给个完整的吧
win2000下面带路径的列出当前的进程,以及对其进行管理!!如杀死进程
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,PsApi,TlHelp32;type
TForm1 = class(TForm)
Button1: TButton;
ListView1: TListView;
Memo1: TMemo;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure NewProcess(ProcessID: DWORD);
var
I: Integer;
Count: DWORD;
ProcHand: THandle;
ModHandles: array[0..$3FFF - 1] of DWORD;
ModInfo: TModuleInfo;
ModName: array[0..MAX_PATH] of char;
Item: TListItem;
var FProcessID:DWORD;
begin
FProcessID:=ProcessID;
ProcHand := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False,
ProcessID);
if ProcHand = 0 then
raise Exception.Create('No information available for this process/driver');
try
EnumProcessModules(ProcHand, @ModHandles, SizeOf(ModHandles), Count);
for I := 0 to (Count div SizeOf(DWORD)) - 1 do
if (GetModuleFileNameEx(ProcHand, ModHandles[I], ModName,
SizeOf(ModName)) > 0) and GetModuleInformation(ProcHand,
ModHandles[I], @ModInfo, SizeOf(ModInfo)) then
with ModInfo do
begin
Item:=Form1.ListView1.Items.Add;
Item.Caption:=ModName;
Item.SubItems.Add(IntToHex(DWord(lpBaseOfDll),8));
Item.SubItems.Add(IntToHex(DWord(SizeOfImage),8));
Item.SubItems.Add(IntToHex(DWord(EntryPoint),8));
end;
finally
CloseHandle(ProcHand);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var SnapShot:THandle;
var NoError:Bool;
var lppe: TProcessEntry32;
begin
SnapShot:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if SnapShot=-1 then
begin
ShowMessage('Error');
Halt;
end;
NoError:=Process32First(Snapshot,lppe);
if NoError=False then
begin
ShowMEssage('Error2');
Halt;
end;
While (NoError=True) do
begin
Memo1.Lines.Add('ProcessId--------'+inttostr(lppe.th32ProcessID));
Memo1.Lines.Add(lppe.szExeFile);
Memo1.Lines.Add('-----------------------------------------------');
NoError:=Process32Next(Snapshot,lppe);
end;
// Process32First(HANDLE hSnapshot, LPPROCESSENTRY32 lppe);
end;procedure TForm1.Button2Click(Sender: TObject);
var HProcess:THandle;
begin
if Edit1.Text<>'' then
begin
NewProcess(StrToInt(Edit1.Text));
end;
end;end.
要杀进程:用terminateprocess!
procedure TForm1.Button2Click(Sender: TObject);
var HProcess:THandle;
begin
if Edit1.Text<>'' then
begin
HProcess:=OpenProcess(PROCESS_ALL_ACCESS,False,StrToInt(Edit1.Text));
if HProcess=0 then
begin
ShowMessage('Open Error');
Halt;
end;
if TerminateProcess(HProcess,0)=True then
begin
ShowMessage('Success');
end
else
begin
ShowMessage('Error Terminate');
end;
end;end;
楼上各位,你们的高见在Win2000下好像不行吧!!!
小弟自己做了个小工具,不过没有用CreateToolhelp32Snapshot,而在用RSAPI.DLL中的相关函数[email protected]
//Win9x下面带路径的列出进程和Win2000下面不带路径的列出进程
procedure TMainForm.ProcessListPro;
var
ok:Bool;
Item: TListItem;
ProcessListHandle:THandle;//进程列表的句柄
ProcessStruct:TProcessEntry32;//进程的结构,进程的信息都在这个结构里面
begin
ProcessLists.Clear;
//利用CreateToolhelp32Snapshot函数取得进程列表的句柄
ProcessListHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPProcess,0);
//首先给出进程结构的大小
ProcessStruct.dwSize:=Sizeof(ProcessStruct);
//得到第一个进程
ok:=Process32First(ProcessListHandle,ProcessStruct);
while integer(ok)<>0 do
begin
if not (ProcessStruct.th32ProcessID in [0,8,164]) then
begin
Item:=ProcessLists.Items.Add;
//由id获路径
Item.Caption:=ProcessIdPath(ProcessStruct.th32ProcessID);
Item.SubItems.Add(IntToStr(ProcessStruct.th32ProcessID));
//并行线程
Item.SubItems.Add(IntToStr(ProcessStruct.cntThreads));
//进程优先级
Item.SubItems.Add(IntToStr(ProcessStruct.pcPriClassBase));
end;
ok:=Process32Next(ProcessListHandle,ProcessStruct);
end;
end;//Win2000下面获得该进程的路径及其调用DLL文件的相关信息
function TMainForm.ProcessIdPath(var ProcessID:DWORD):string;
var
i : Integer;
Count : DWORD;
ProcHand : THandle;
ModHandles: array [0..$3FFF - 1] of DWORD;
ModInfo : TModuleInfo;
ModName : array [0..MAX_PATH] of Char;
// Item : TListItem;
FProcessID: DWORD;
begin
FProcessID:=ProcessID;
ProcHand := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False,
ProcessID);
if ProcHand <> 0 then
begin
try
EnumProcessModules(ProcHand, @ModHandles, SizeOf(ModHandles), Count);
for i := 0 to (Count div SizeOf(DWORD)) - 1 do
if (GetModuleFileNameEx(ProcHand, ModHandles[i], ModName,
SizeOf(ModName)) > 0) and GetModuleInformation(ProcHand,
ModHandles[i], @ModInfo, SizeOf(ModInfo)) then
if i=0 then Result:=ModName;
{ //以下获得该进程调用的dll文件及其相关信息
with ModInfo do
begin
Item:=ListView1.Items.Add;
Item.Caption:=ModName;
//调用dll文件的基地址
Item.SubItems.Add(IntToHex(DWord(lpBaseOfDll),8));
Item.SubItems.Add(IntToHex(DWord(SizeOfImage),8));
//调用dll文件的入口地址
Item.SubItems.Add(IntToHex(DWord(EntryPoint),8));
}
finally
CloseHandle(ProcHand);
end;
end;
end;
本人水平有限不令赐教,不胜感激哟!谢谢了
不过好象csdn上面的人有个很奇怪的习惯就是拿到东西就走人不给分/
So Cheep......
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, ComCtrls,
StdCtrls, PSAPI, ImgList;
type
TFMain = class(TForm)
GroupBox1: TGroupBox;
ListView1: TListView;
BEnumProcesses: TButton;
BEnumDrivers: TButton;
BExit: TButton;
procedure BEnumProcessesClick(Sender: TObject);
procedure BEnumDriversClick(Sender: TObject);
procedure ListView1DblClick(Sender: TObject);
procedure BExitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FMain: TFMain;
implementation
uses unit2;
{$R *.DFM}
//列举进程procedure TFMain.BEnumProcessesClick(Sender: TObject);
var
processIDs: array[0..$3FFF - 1] of DWORD; //进程ID
Count: DWORD;
i: integer;
ProcHand: THandle; //进程的句柄
ModHand: HMODULE; //模块的句柄
ModName: array[0..MAX_PATH] of char; //模块文件名
begin
GroupBox1.Caption := '正在运行的所有进程,鼠标双击有进程的详细信息';
ListView1.Items.Clear;
//列举所有正在运行的进程
if not EnumProcesses(@processIDs, SizeOf(processIDs), Count) then
raise Exception.Create('列举进程出错,确认是否安装了PSAPI.DLL!');
for i := 0 to (Count div Sizeof(DWORD)) - 1 do
begin
ProcHand := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
False, processIDs[i]); //查询方式打开进程
if ProcHand > 0 then
try
//列举进程的首模块
if EnumProcessModules(Prochand, @ModHand, sizeof(ModHand), Count)
//获取模块的文件名
then
if GetModuleFileNameEx(Prochand, ModHand, ModName,
SizeOf(ModName)) > 0 then
begin
with ListView1.Items.Add, SubItems do
begin
Caption := ModName;
Data := Pointer(processIDs[I]); //保存进程的ID
Add(IntToStr(processIDs[I]));
end;
end;
finally
CloseHandle(ProcHand);
end;
end;
end;
//列举设备驱动程序procedure TFMain.BEnumDriversClick(Sender: TObject);
var
ImageBase: array[0..$3FFF - 1] of Pointer;
i: integer;
Count: DWORD;
DrvName: array[0..MAX_PATH] of char;
begin
GroupBox1.Caption := '系统加载的所有设备';
Listview1.Items.Clear;
if not EnumDeviceDrivers(@ImageBase, SizeOf(ImageBase), Count) then
raise Exception.Create('列举设备出错,确认是否安装了PSAPI.DLL!');
for i := 0 to (Count div Sizeof(DWORD)) - 1 do
begin
if GetDeviceDriverFileName(imageBase[I], DrvName,
SizeOf(DrvName)) > 0 then
with ListView1.Items.Add do
begin
Caption := DrvName;
SubItems.Add('$' + IntToHex(Integer(ImageBase[I]), 8));
end;
end;
end;
//翻译页面的类型function MemoryTypeToString(Value: DWORD): string;
const
TypeMask = DWORD($0000000F);
begin
Result := '';
case Value and TypeMask of
1: Result := 'Read-only';
2: Result := 'Executable';
4: Result := 'Read/write';
5: Result := 'Copy on write';
else
Result := 'Unknown';
end;
if Value and $100 <> 0 then
Result := Result + ', Shareable';
end;
//某一进程的模块、页面等信息procedure TFMain.ListView1DblClick(Sender: TObject);
const
AddrMask = DWORD($FFFFF000);
var
ProcHand: THandle; //进程的句柄
ModHand: array[0..1024] of HMODULE; //模块的句柄
ModName: array[0..MAX_PATH] of char; //模块文件名
ProcessID, Count: DWORD;
i: integer;
WSPtr: Pointer;
WorkingSet: array[0..$3FFF - 1] of DWORD;
ModInfo: TModuleInfo; //模块的信息
MapFileName: array[0..MAX_PATH] of char;
begin
if Listview1.Selected <> nil then
if Listview1.Selected.Data <> nil then
with FDetail do
begin
MoudlesLV.items.clear; //模块的ListView清空
MemoryLV.Items.Clear; //内存的ListView清空
ProcessID := DWORD(Listview1.Selected.Data);
ProcHand := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
False, processID); //查询方式打开进程
LProcessID.caption := Listview1.Selected.SubItems[0];
LPriority.caption := inttostr(GetPriorityClass(ProcHand));
//进程的优先级
EModule.Text := Listview1.Selected.Caption;
//列举进程所有的模块
EnumProcessModules(Prochand, @ModHand, sizeof(ModHand), Count);
for i := 1 to (Count div Sizeof(DWORD)) - 1 do
if (GetModuleFileNameEx(ProcHand, ModHand[I], ModName,
SizeOf(ModName)) > 0) and GetModuleInformation(ProcHand,
ModHand[I], @ModInfo, SizeOf(ModInfo)) then
//GetModuleInformation()获取模块的信息
with ModInfo, MoudlesLV.items.add, SubItems do
begin
Caption := ModName; //模块文件名
Add('$' + IntToHex(Integer(lpBaseOfDll), 8));
//模块的基地址
Add(inttostr(SizeofImage));
//模块的占的字节数大小
add('$' + IntToHex(Integer(EntryPoint), 8));
//模块的Entry Point进入口
end; if QueryWorkingSet(ProcHand, @WorkingSet, SizeOf(WorkingSet)) then
//获取所有内存页面信息
for I := 1 to WorkingSet[0] do
begin
WSPtr := Pointer(WorkingSet[I] and AddrMask);
MapFileName[0] := #0;
GetMappedFileName(ProcHand, WSPtr, MapFileName, SizeOf(MapFileName));
//获取所在页面内存映射的文件名
with MemoryLV.items.add, subitems do
begin
caption := '$' + IntToHex(Integer(WSPtr), 8); //页面的地址
add(MemoryTypeToString(WorkingSet[I])); //页面类型
add(MapFileName); //内存映射的文件名
end;
end;
CloseHandle(ProcHand);
Show;
end;
end;procedure TFMain.BExitClick(Sender: TObject);
begin
Close;
end;
end.
哈哈:)
有空到我主页作客:http://lovejingtao.126.com