-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathGetProcessName_Method2.pas
More file actions
46 lines (37 loc) · 1.08 KB
/
GetProcessName_Method2.pas
File metadata and controls
46 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Jean-Pierre LESUEUR (@DarkCoderSc)
// ...
uses psAPI;
// ...
function PhysicalToVirtualPath(APath : String) : String;
var i : integer;
ADrive : String;
ABuffer : array[0..MAX_PATH-1] of Char;
ACandidate : String;
begin
{$I-}
for I := 0 to 25 do begin
ADrive := Format('%s:', [Chr(Ord('A') + i)]);
///
if (QueryDosDevice(PWideChar(ADrive), ABuffer, MAX_PATH) = 0) then
continue;
ACandidate := String(ABuffer).ToLower();
if String(Copy(APath, 1, Length(ACandidate))).ToLower() = ACandidate then begin
Delete(APath, 1, Length(ACandidate));
result := Format('%s%s', [ADrive, APath]);
end;
end;
{$I+}
end;
function GetCurrentProcessImagePath() : String;
var AFileName : Array[0..MAX_PATH -1] of Char;
begin
ZeroMemory(@AFileName, MAX_PATH);
///
GetMappedFileName(
GetCurrentProcess(),
Pointer(GetModuleHandle(nil)),
AFileName,
MAX_PATH
);
result := PhysicalToVirtualPath(UnicodeString(AFileName));
end;