If p[0] holds the ProcessID, that can be passed directly to OpenProcess without the need for a FindWindow or GetWindowThreadProcessId call. I forgot about the Process object.