I need to check whether a program (xyz.exe) is running, but only for the current user. Whatever method is used cannot require elevated rights, and has to run fast (so WMI is out).
Process.GetProcessesByName("xyz")
returns results for "xyz" for all logged in users... but I only care about the current user.
Ideas?
Use the current process SessionId
to filter the list of processes:
public static bool IsProcessRunningSameSession(string processName)
{
var currentSessionID = Process.GetCurrentProcess().SessionId;
return Process.GetProcessesByName(processName).Where(p => p.SessionId == currentSessionID).Any();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With