0

We are creating a UWP application which is intended for Side loading only. At various times this application needs to reboot the PC (it's desktop only), to do this we intend to use LaunchFullTrustProcessForCurrentAppAsync() to call a simple external EXE which uses Process.Start("shutdown") to reboot the PC.

We have created the EXE called RebootPC.exe and on it's own it works fine.

We now include it in our UWP project:

First we add the desktop and rescap namespaces to our project and we also add rescap to our IgnorableNamspaces

xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" 
     xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 
     IgnorableNamespaces="uap mp uap5 rescap">

Then, we then modify the Extension section to include our EXE, we know we cannot put the EXE in our project root as C# compiler removes it so we have put it in a sub folder (in this case \Assets). We also set the EXE's type to 'Content' and 'Copy always' in the Solution explorer

<desktop:Extension Category="windows.fullTrustProcess" Executable="Assets\RebootPC.exe">
      <desktop:FullTrustProcess>
        <desktop:ParameterGroup GroupId="rebooter" Parameters=""/>
      </desktop:FullTrustProcess>
    </desktop:Extension>

finally in the manifest we add rescap to the Capabilities section - we know it has to be first in the list otherwise you get a manifest error when packaging

<Capabilities>
<rescap:Capability Name="runFullTrust"/>
<Capability Name="internetClient" />
<DeviceCapability Name="bluetooth" />
<DeviceCapability Name="radios" />

OK, so the manifest is changed. We now go to our C# code:

In that we perform the following:

if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
            {
                try
                {
                    await Windows.ApplicationModel.FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();

                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

            }

When we build and run the project in Visual Studio it seems to work fine, under the intended circumstances the PC will reboot as intended.

The problem comes when we try to package it for installation on other PCs. We use Store->Create App Packages (remember this application is for side loading only).

The creation of the package works fine and we can install it on other PCs with no problem. The problem is that when we run the Application and it comes time to run the external EXE to reboot the PC a command window opens but we get an exception saying "System can't find c:\users.......\Assets\RebootPC.exe"

So, even though the packaging is done without error and even though we have set the properties of RebootPC.exe to 'Content' and 'Copy always' it is either not being included in the package or not being installed along with the App?

So, does anyone know how we can check if it is being included in the package? and if so how we can check if and where it is being installed on the target machine? or has anyone else had this issue and found the solution?

This has had us baffled for days and is driving us crazy!!!

UPDATE: I think the issue may not be that RebootPC.exe can't be found but rather shutdown.exe - If this is the case then it's a bit of a school boy error!!! Anyway, I will sort this and see if that fixes the issue

I will leave the rest of the question up as it might provide useful information for others

1
  • Make sure your exe is in your appx folder of your project it will work fine. *Project*/bin/x86/debug/Appx and change Executable="Assets\RebootPC.exe" to Executable="RebootPC.exe". This solved problem for me
    – Vignesh
    Commented Feb 15, 2019 at 7:26

2 Answers 2

1

As Mentioned in the official sample the exe file has to in the Appx folder of your project

Make sure the RebootPC.exe was copied to the Appx folder - UWP\bin\x64\Release\AppX if not rebuild the solution or copy it manually.

https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/AppServiceBridgeSample#builddeploy-and-run-the-sample

-1
            try
            {
                await Windows.ApplicationModel.FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("rebooter");

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

        }
1
  • You should include an explanation for how and why your answer helps. You should also probably include a disclaimer that catching all exceptions is an anti-pattern
    – Marie
    Commented Feb 25, 2022 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.