0 Replies - 1272 Views - Last Post: 06 June 2012 - 09:23 PM

#1 paperclipmuffin  Icon User is offline

  • Disassembling...
  • member icon

Reputation: 13
  • View blog
  • Posts: 944
  • Joined: 16-April 09

Get Process Handle by Name

Posted 06 June 2012 - 09:23 PM

Description: Requires a reference to System.DiagnosticsTakes string ProcessName (eg "taskmgr") as argument and returns IntPtr[] Handles of all running processes of that name. This allows you to easily interact with them.
public IntPtr[] GetProcessHandle(string ProcessName)
{
	// Get all processes of name ProcessName
	Process[] ProcList = Process.GetProcessesByName(ProcessName);
	
	// Create an array for the handles
	IntPtr[] Handles = new IntPtr[ProcList.Length];
	
	// Fill handles array with handles of processes
	for (int i = 0; i < Handles.Length; i++) {
		Handles[i] = ProcList[i].Handle;
	}
	
	return Handles;
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1