Getting process name with extension name(.exe per example)
I'm making a program and I want to add all processes to a listbox, for this, I used the following code:
foreach(Process p in Process.GetProcesses())
{
listBox1.Items.Add(p.ProcessName);
}
This adds the processes name like
But instead, I would like to see the processes with their extensions for example: chrome.exe or iexplorer.exe as there are some programs that aren't .exe like XTrap.xt
Edit: I also tried
listBox1.Items.Add(p.ModuleMain.FileName);
But it throws a Win32Exception: Access Denied
Set the app to run as x64 and as admin user, right click run as or run VS as admin.
You can use Path.GetFileName(p.ModuleMain.FileName) to get filename from full path.