Having this code:
StorageFolder storageFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(file.folderToken);
StorageFile storageFile = await storageFolder.CreateFileAsync("run.exe", CreationCollisionOption.ReplaceExisting);
await FileIO.WriteBytesAsync(storageFile, Properties.Resources.youtube_dl1);
I'm able to create a file at the user picked location using the folder token. I now want to run the file within a process:
Process checkforupdates = new Process();
checkforupdates.StartInfo.FileName = storageFile.Path;
checkforupdates.StartInfo.Arguments = "-x https://www.youtube.com/watch?v=uzr5jm9ueja";
checkforupdates.StartInfo.UseShellExecute = false;
checkforupdates.StartInfo.RedirectStandardOutput = true;
checkforupdates.StartInfo.RedirectStandardOutput = true;
checkforupdates.StartInfo.RedirectStandardError = true;
checkforupdates.StartInfo.CreateNoWindow = true;
checkforupdates.EnableRaisingEvents = true;
checkforupdates.OutputDataReceived += (s, er) =>
{
Debug.WriteLine("dsds" + er.Data);
};
checkforupdates.Start();
checkforupdates.BeginOutputReadLine();
checkforupdates.BeginErrorReadLine();
checkforupdates.WaitForExit();
This works fine if I use:
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
But as long as I use the user selected folder, I receive an exception. I'm sure that the exception is UnauthorizedAccessException but I will need a bunlded exe to unpack inside a folder and then run commands in order to produce files inside the user selected folder. While doing that I need to parse the output of the command line utility that I'm running.
Any way to do that?
You can do this via the "Desktop Bridge" to pack a Win32 app inside a UWP app package and then run with the FullTrustProcessLauncher and communicate with it via app services. Here is a samples.