3 Replies - 7050 Views - Last Post: 19 June 2009 - 11:10 AM Rate Topic: -----

#1 conanlive   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-December 08

Getting Process ID based on Session ID

Posted 18 June 2009 - 10:44 AM

How to get the Process ID based on Session ID??


Process xxx = new Process();
xxx.StartInfo.FileName = "XXXXXXX.EXE";
xxx.Start();
int PID = Process.GetProcessesByName(xxx.ProcessName)[0].Id;

This PID as shown above I get from another session is not exactly.

Thus, the process from another session is killed . But, I want to

kill my process in my session. How to get it ?? Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Getting Process ID based on Session ID

#2 djkitt   User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 192
  • Joined: 22-May 08

Re: Getting Process ID based on Session ID

Posted 18 June 2009 - 11:23 AM

So, you could just give up on using GetProcessByName().

Either keep the Process variable around until you want to kill the process

-or-

Save the process Id and use GetProcessById to retieve the process later for killing.


Hope this helps,

Kitt
Was This Post Helpful? 0
  • +
  • -

#3 baavgai   User is online

  • Dreaming Coder
  • member icon


Reputation: 7483
  • View blog
  • Posts: 15,510
  • Joined: 16-October 07

Re: Getting Process ID based on Session ID

Posted 18 June 2009 - 11:23 AM

Process xxx = new Process(); 
xxx.StartInfo.FileName = "XXXXXXX.EXE"; 
xxx.Start(); 
int PID = Process.GetProcessesByName(xxx.ProcessName)[0].Id; 



You are limiting your results to one return. Why not just look:

foreach(Process p in Process.GetProcessesByName(xxx.ProcessName)) {
	if (p.SessionId==searchId) { return p; }
}
return null;


Was This Post Helpful? 0
  • +
  • -

#4 conanlive   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-December 08

Re: Getting Process ID based on Session ID

Posted 19 June 2009 - 11:10 AM

View Postbaavgai, on 18 Jun, 2009 - 10:23 AM, said:

Process xxx = new Process(); 
xxx.StartInfo.FileName = "XXXXXXX.EXE"; 
xxx.Start(); 
int PID = Process.GetProcessesByName(xxx.ProcessName)[0].Id; 



You are limiting your results to one return. Why not just look:

foreach(Process p in Process.GetProcessesByName(xxx.ProcessName)) {
	if (p.SessionId==searchId) { return p; }
}
return null;





If there are two same image names (process name) in my session, it directly kills all of them.

BUT, I want to kill one of them based on session ID and PID in my session.

So, i need to get PID from my session and then kill it. This is because sometimes it gets PID from different session and then kill wrong process in another session.

That's why I want to get PID from my session, and then only kill one of them based PID & session ID.

Any solution?? thanks!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1