我知道CSDN藏龙卧虎,各位兄台,能根据进程名得到程序完整路径吗?
解决方案 »
- 如果查询表名不存在,该怎么样捕捉到这个错误呢?
- 现在delphi7开发C/S架构的数据库存取系统都用什么技术的啊
- 向win.ini写数据不好使
- 为什么说Adodataset1:Field name missing?
- 请教:d6+win200下开发编译的程序,在win98下运行遇到的问题
- 两个简单的老问题,可是一直没弄出正确答案,希望大家给个详细点的结果,谢谢,dbgrid点击标题栏自动排序,还有字段中是'0''1'这种数据的读取
- 那位朋友知道如何在网络上截取一个信息(数据包)
- paradox与tadotable连接问题
- Delphi中怎样实现接口?
- 大侠帮忙, 一个字符串怎么样才能转换成一个字节数组? 我是菜鸟只有22分了
- 系统低层登陆问题
- fastreport的打印问题
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,TLHELP32, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
FSnapshotHandle : THandle;
public
function GetProcessID(ProcessName: string): Dword;
end;var
Form1: TForm1;implementation{$R *.dfm}function Tform1.GetProcessID(ProcessName: string): Dword;
var
Ret: BOOL;
s: string;
FProcessEntry32: TProcessEntry32;
begin
Result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
Ret := Process32First(FSnapshotHandle, FProcessEntry32);
while Ret do
begin
s := ExtractFileName(FProcessEntry32.szExeFile);
if (AnsicompareText(Trim(s),Trim(ProcessName))=0) then
begin
Result := FProcessEntry32.th32ProcessID;
Break;
end;
Ret := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;procedure TForm1.Button1Click(Sender: TObject);
var
PID: integer;
ModuleListHandle: Thandle;
ModuleStruct: TMODULEENTRY32;
Yn: boolean;
begin
//假设你要根据delphi的进程名delphi32.exe来得到他的路径全称
edit1.Text := 'delphi32.exe';
if Edit1.Text = '' then exit;
pid := GetProcessID(edit1.Text);
ModuleListHandle := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pID);
ModuleStruct.dwSize := sizeof(ModuleStruct);
yn := Module32First(ModuleListHandle, ModuleStruct);
if yn then ShowMessage(ModuleStruct.szExePath)
else ShowMessage('找不到');
CloseHandle(ModuleListHandle);
end;
end.
非常感谢
我正好要用到,hehe