Наконец-то дошло.
В файле манифеста приложения я поместил это:
<Extensions>
<desktop:Extension Category="windows.fullTrustProcess" Executable="ConsoleApp1.exe">
<desktop:FullTrustProcess>
<desktop:ParameterGroup GroupId="RestartPC" Parameters="c:\mypath\Powershelldb.exe"/>
<desktop:ParameterGroup GroupId="db" Parameters="c:\mypath\shutdowndb.exe"/>
</desktop:FullTrustProcess>
Затем я создал консольное приложение c ++, которое имеет следующий код:
using System;
using System.IO;
using System.Diagnostics;
using System.Reflection;
class Program
{
static void Main(string[] args)
{
try
{
if (args.Length != 0)
{
string executable = args[2];
string path=Assembly.GetExecutingAssembly().CodeBase;
string directory=Path.GetDirectoryName(path);
Process.Start(directory+"\\"+executable);
Process.Start(executable);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
Затем я создал исполняемый файл, который хотел запустить, как показано ниже:
#include "stdafx.h"
#include <iostream>
int main()
{
system("start powershell.exe -command Restart-Computer");
return 0;
}
В своем приложении UWP я затем использовал следующее:
private async void doSomething()
{
string commandID = "db";
ApplicationData.Current.LocalSettings.Values["parameters"] = commandID;
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(commandID);
}
Затем Powershell запустил и выключил мой компьютер.Очевидно, что это не является целью всего этого, но я хотел протестировать команды powershell:)
Я нашел полезную нить здесь , которая очень помогла.
Спасибо Стефануза его полезный вклад также