delphi根据进程ID获取进程路径


本文整理自网络,侵删。

 
unit Unit1;
interfaceuses
     Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, psapi;type

     TForm1 = class(TForm)
       Button1: TButton;
       procedure Button1Click(Sender: TObject);
       function GetProcessPath(ProcessID: DWORD): string;
     private
       { Private declarations }
     public
       { Public declarations }
     end;
var
     Form1: TForm1;
implementation
{$R *.dfm}

function TForm1.GetProcessPath(ProcessID: DWORD): string;
var
     Hand: THandle;
     ModName: Array[0..Max_Path-1] of Char;
     hMod: HModule;
     n: DWORD;
begin
     Result:='';
     Hand:=OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
                           False,
                           ProcessID);
     if Hand>0 then
     try
       ENumProcessModules(Hand,@hMod,Sizeof(hMod),n);
       if GetModuleFileNameEx(Hand,hMod,ModName,Sizeof(ModName))>0 then
         Result:=ExtractFilePath(ModName);
     except end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
s:=GetProcessPath(852);
showmessage(s);
end;end.

相关阅读 >>

Delphi使用idhttp模拟提交页面方法总结

Delphi中转向语句break,continue,exit的作用

Delphi 合并动态数组

Delphi动态创建控件的例子

Delphi d10.x 在安卓app开发中使用jar包的注意事项

Delphi 两种登录界面验证写法

Delphi和outputdebugstring

Delphi readprocessmemory writeprocessmemory读写内存

Delphi工具之winsight

Delphi 如何将access的ole对象字段存储的bmp图象显示出来

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...