I am trying to get the path from running processes in Windows 10 without success. Here is the code I am using:
procedure GetPathFromProcessList(List: TStringList);
var
Shot: THandle;
Proc: THandle;
Data: TProcessEntry32;
Path: array[0..MAX_PATH - 1] of Char;
begin
Shot := CreateToolHelp32Snapshot(TH32CS_SNAPALL, 0); //TH32CS_SNAPPROCESS
if (Shot <> 0) then
try
List.Sorted := True;
List.Duplicates := dupIgnore;
List.BeginUpdate;
if (Process32First(Shot, Data)) then
repeat
// PROCESS_QUERY_LIMITED_INFORMATION = $1000
Proc := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, Data.th32ProcessID);
if (Proc <> 0) then
try
if (GetModuleFileNameEx(Proc, 0, Path, MAX_PATH) <> 0) then
List.Add(LowerCase(Path));
finally
CloseHandle(Proc);
end;
until (not Process32Next(Shot, Data));
List.EndUpdate;
finally
CloseHandle(Shot);
end;
end;
My application asks for elevated privileges and I already tried to use PROCESS_QUERY_LIMITED_INFORMATION ($1000) in OpenProcess, but the problem is the same.
It doesn't give me any error, but list is empty in Windows 10. In Windows 7 it works without problem...
Please, anyone knows what is going on? Thank you!