Processes for only current user

This commit is contained in:
Vladimir
2024-05-16 03:49:44 +04:00
parent 6b9c750042
commit 2561567cf5

View File

@@ -1,6 +1,8 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using RelaunchProcess.Properties; using RelaunchProcess.Properties;
@@ -29,6 +31,7 @@ namespace Process_Auto_Relaunch
{ {
LoadOldState(); LoadOldState();
//MessageBox.Show(Environment.UserDomainName);
CheckProgramState(); CheckProgramState();
} }
@@ -179,7 +182,22 @@ namespace Process_Auto_Relaunch
private bool ProcessByNameIsRuning(string name) private bool ProcessByNameIsRuning(string name)
{ {
return Process.GetProcessesByName(name).Length > 0; var sessionid = Process.GetCurrentProcess().SessionId;
var processes = Process.GetProcessesByName(name);
foreach (var process in processes)
{
if (!process.Responding)
{
MessageBox.Show($"Âîçìîæíî ïðîöåññ {process.ProcessName} çàâèñ.");
}
Debug.WriteLine($"Found proces: {process.ProcessName}. Session Id: {process.SessionId}. Current Session Id: {sessionid}");
if (process.SessionId == sessionid)
return true;
}
Debug.WriteLine($"Process {name} for current session id {sessionid} not found");
return false;
} }
private void ProcessStart(string path, string args) private void ProcessStart(string path, string args)