Terminating a process created with spawnv

I don't experience any processes at all, but what I'm set up should be very simple. All I do is create 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 amount of time. However, the returned spawnId is not what I need if called, for example taskkill /PID [number] /F

.

I tried using otherId2 = GetWindowThreadProcessId((HWND)spawnId,OUT otherId1)

, but again, neither otherId1

or otherId2

nor gave the correct PID.

If anyone can help me I would be grateful. Regards, Roald

+1


a source to share


1 answer


From MSDN :

The return value from asynchronous _spawnv

or _wspawnv

( _P_NOWAIT

or _P_NOWAITO

specified for mode) is a handle to the process.



Once you have a handle to a process, you can use TerminateProcess

.

Handle types are not interchangeable. You cannot print a handle to a process before HWND

and suddenly become a handle to a window.

+1


a source







All Articles