# Call TerminateProcess on Unreal game created from CreateProcess

**URL:** <https://forums.unrealengine.com/t/call-terminateprocess-on-unreal-game-created-from-createprocess/477080>\
**Category:** C++\
**Tags:** windows-10, unreal-engine, question, process\
**Created:** [January 11, 2021, 1:12pm UTC](https://forums.unrealengine.com/t/call-terminateprocess-on-unreal-game-created-from-createprocess/477080 "2021-01-11T13:12:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunoleos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@brunoleos](https://forums.unrealengine.com/u/brunoleos)\
**Post date:** [January 11, 2021, 1:12pm UTC](https://forums.unrealengine.com/t/call-terminateprocess-on-unreal-game-created-from-createprocess/477080/1 "2021-01-11T13:12:45Z")

</div>

Call TerminateProcess on Unreal game created from CreateProcess

I have two distinct applications: An Unreal packaged game (I will call it “ **game** ”) and another Windows application (wich I will call “ **app** ”) that creates the game with CreateProcess and tries to kill it with TerminateProcess, both from Windows SDK (processthreadsapi.h).

I call CreateProcess in the app with the code:

```
void CreateUnrealServerProcess()
{
  STARTUPINFO si;
  PROCESS_INFORMATION pi;

  ZeroMemory(&si, sizeof(si));
  si.cb = sizeof(si);
  ZeroMemory(&pi, sizeof(pi));

  bool processCreated = CreateProcess(
    NULL,
    const_cast<char*>(fullExecutablePath.c_str()),
    NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi
  ) != 0;

  serverProcessHandle = pi.hProcess;
}

```

And after the game is loaded and running, I’m trying to kill it with:

```
bool processTerminated = TerminateProcess(serverProcessHandle, 0);

```

But the game window don’t get closed, and the process keeps alive.

My game uses ObjectDeliverer, configured to act as a TCP server, and has just a first person shooter template with a landscape.

The return from TerminateProcess is no error.

Any hints on what is happening? I know I could send a message to the game with TCP to finish it from Unreal, but now I need to kill it from the process that created the game.

---

<div class="post-metadata">

**Author:** ![num3ric](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@num3ric](https://forums.unrealengine.com/u/num3ric)\
**Post date:** [January 11, 2021, 10:38pm UTC](https://forums.unrealengine.com/t/call-terminateprocess-on-unreal-game-created-from-createprocess/477080/2 "2021-01-11T22:38:44Z")

</div>

Not a complete answer, but this only occurs when packaging in development mode (which makes me think the game may be running as subprocess, without job object assignment).

`::TerminateProcess` does work as intended on executables packaged in shipping mode however.

---

<div class="post-metadata">

**Author:** ![num3ric](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@num3ric](https://forums.unrealengine.com/u/num3ric)\
**Post date:** [January 11, 2021, 10:43pm UTC](https://forums.unrealengine.com/t/call-terminateprocess-on-unreal-game-created-from-createprocess/477080/3 "2021-01-11T22:43:12Z")

</div>

Related note: neither `WM_CLOSE` nor `WM_QUIT` messages work however.
