uses Windows, PsAPI;
var
gDir: array[0..9999]of Char;
function ctGetExeDir: PChar;
var
hPro, hMod: Cardinal;
count: Cardinal;
begin
result:= @gDir[0];
if gDir[0] <> #0 then Exit;
ZeroMemory(@gDir[0],SizeOf(gDir));
hPro:= OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,False,GetCurrentProcessID);
if hPro <> 0 then try
if EnumProcessModules(hPro,@hMod,4,count) then begin
count:= GetModuleFileName(hMod,@gDir[0], SizeOf(gDir));
if count >0 then begin
// success
end;
finally
CloseHandle(hPro);
end;
end;
供你参考