title: UWP FullTrustProcess - actually controlling the process
body: <p>In WPF, I have used this code to control the process of an external .exe file:</p>
  
  <pre><code>ProcessStartInfo info = new ProcessStartInfo()
  {
      Verb = "runas",
      FileName = executePath,//Client.exe path within the WPF application
      UseShellExecute = false,
      RedirectStandardError = true,
      RedirectStandardOutput = true,
  };
  
  Process scanProcess = new Process
  {
      StartInfo = info,
      EnableRaisingEvents = true
  };
  
  int procId = Process.GetCurrentProcess().Id;
  Process[] existingProcess = Process.GetProcessesByName("Client.exe");
  foreach (Process process in existingProcess)
  {
      if (process.Id == procId)
      {
          continue;
      }
  
      return;//don't run, might have tried to start double
  }
  
  scanProcess.Start();
  scanProcess.Exited += (s, e) =&gt; GoBack();
  
  windowHandle = IntPtr.Zero;
  IntPtr buttonHandle = IntPtr.Zero;
  while (buttonHandle == IntPtr.Zero)//wait till process is fully started, we wait for a button the be available because then we know it is ready
  {
      windowHandle = HardwareApi.GetForegroundWindow();
      buttonHandle = HardwareApi.FindWindowEx(windowHandle, IntPtr.Zero, "TPanel", "Start");
  
  }
  
  Rectangle rect = new Rectangle(0, 0, 0, 0);
  HardwareApi.GetWindowRect(windowHandle, ref rect);
  //move window to correct position
  var tempX = 500;
  var tempY = 600;
  HardwareApi.SetWindowPos(windowHandle, new IntPtr(-1), 0, 0, 0, 0, 3u);
  HardwareApi.MoveWindow(windowHandle, (int)tempX, (int)tempY, rect.Width, rect.Height - 55, true);
  </code></pre>
  
  <p>As you see, quite a bit of intense process controlling. <code>HardwareApi</code> is just a collection of <code>user32.dll</code> methods using <code>DllImport</code>.</p>
  
  <p>Now I don't mind if not all of these functionalities are possible, but at least I need to be able to start the process and stop it/kill it from out the new UWP application.</p>
  
  <p>So I went through the process of creating an UWP application and a Package application, I followed <a href="https://stefanwick.com/2018/04/06/uwp-with-desktop-extension-part-1/" rel="nofollow noreferrer">this blog</a>, provided by <a href="https://stackoverflow.com/a/55978324/2901207">this answer on stackoverflow</a>. What is importantly different is that I do not have a separate Visual Studio Project of the external Client.exe, so I did what the mentioned answer said: Copy the Client.exe file (and the dependent files) into the Package project.</p>
  
  <p>Solution view:</p>
  
  <p><a href="https://i.stack.imgur.com/VN765.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VN765.png" alt="enter image description here"></a></p>
  
  <p>Package.appxmanifest of the Package project includes this part:</p>
  
  <pre><code>  &lt;Applications&gt;
      &lt;Application Id="App"
       ....
        &lt;Extensions&gt;
          &lt;desktop:Extension Category="windows.fullTrustProcess" Executable="Rss\Hardware\Software\RedFolder\Client.exe"/&gt;
        &lt;/Extensions&gt;
      &lt;/Application&gt;
    &lt;/Applications&gt;
  
    &lt;Capabilities&gt;
      &lt;Capability Name="internetClient" /&gt;
      &lt;rescap:Capability Name="runFullTrust" /&gt;
     &lt;rescap:Capability Name="allowElevation" /&gt;
    &lt;/Capabilities&gt;
  </code></pre>
  
  <p>And within the UWP application, I somewhere start the <code>FullTrustProcess</code></p>
  
  <p>Don't forget to go to <code>Add Reference</code>-> Universal Windows -> Extensions -> <code>Windows Desktop Extensions for the UWP (latest version)</code> and add the reference</p>
  
  <pre><code>if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
  {
      await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
  }
  </code></pre>
  
  <p>So this all works fine, so now the question is how I can do the following things:</p>
  
  <ol>
  <li>Check if the process is running</li>
  <li>Close the process at a certain time from within the UWP application</li>
  <li>Move the window to a certain on-screen position (or use other <code>user32.dll</code>-like functions.</li>
  </ol>
  
  <p>As per my understanding, App Service within UWP doesn't seem to be a solution, I can't modify the external .exe in such a way that it would receive/connect. If an App Service can be used from only the UWP-side to control a process then that would be great.</p>