views:

92

answers:

1

Hi everyone, I'm not experienced with processes at all, but what I'm set to to should be really simple. All I do is spawn a process like this:

int spawnId = spawnv(_P_NOWAIT,"wgetlocal.exe",my_env);

Now, what I want to do is kill this program after a certain time. However, the returned spawnId is not what I need when for instance calling taskkill /PID [number] /F.

I've tried using otherId2 = GetWindowThreadProcessId((HWND)spawnId,OUT otherId1) but again, neither otherId1 or otherId2 give the correct PID.

If anyone could help me witht his, I'd be vary thankfull. Regards, Roald

+1  A: 

From MSDN:

The return value from an asynchronous _spawnv or _wspawnv (_P_NOWAIT or _P_NOWAITO specified for mode) is the process handle.

When you have a process handle, you can use TerminateProcess.

Types of handles are not interchangeable. You cannot type-cast a process handle to HWND and have it suddenly be a window handle.

Rob Kennedy