get current session ID
-
Hi all Where would i look to get the session ID of the program I made I can find the session ID or other process's and i want to compare them to the session ID of my program to make sure its okay to kill them and not accidentally kill a process on another session.
-
Hi all Where would i look to get the session ID of the program I made I can find the session ID or other process's and i want to compare them to the session ID of my program to make sure its okay to kill them and not accidentally kill a process on another session.
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessesByName("devenv");
p.SessionId; //if you want sessionid
p.Id; //if you want PID -
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessesByName("devenv");
p.SessionId; //if you want sessionid
p.Id; //if you want PID -
will that work? lets say i have 10 people logged on and they are all running the same program (windowsapplicaiton3.exe) for example wont it return p.sessionID for all 10 people? i guess what im asking is how does my program know its own session state?
Why don't you give it a try?
-
i also found this [DllImport("kernel32.dll")] static extern bool ProcessIdToSessionId(uint dwProcessId, out uint pSessionId); static void Main(string[] args) { Process _currentProcess = Process.GetCurrentProcess(); uint _processID = (uint)_currentProcess.Id; uint _sessionID; bool _result = ProcessIdToSessionId(_processID, out _sessionID); Console.WriteLine("ProcessIdToSessionId Result: " + _result.ToString()); Console.WriteLine("Process ID = " + _processID.ToString()); Console.WriteLine("Session ID = " + _sessionID.ToString()); Console.ReadLine(); } but im unclear on how to implement it im still a little green with .net
-
Why don't you give it a try?
-
will that work? lets say i have 10 people logged on and they are all running the same program (windowsapplicaiton3.exe) for example wont it return p.sessionID for all 10 people? i guess what im asking is how does my program know its own session state?
You can get the session if of your application using
System.Diagnostics.Process.GetCurrentProcess().SessionId;
andSystem.Diagnostics.Process.GetCurrentProcess().Id;
Using the PID of your current process, you can kill your process. -
You can get the session if of your application using
System.Diagnostics.Process.GetCurrentProcess().SessionId;
andSystem.Diagnostics.Process.GetCurrentProcess().Id;
Using the PID of your current process, you can kill your process.