UWP 可以使用 StorageFile 运行进程吗?

有这个代码:


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);

我可以使用文件夹令牌在用户选择的位置创建一个文件。我现在想在一个进程中运行该文件:


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();  

如果我使用,这很好用:


 StorageFolder storageFolder = ApplicationData.Current.LocalFolder;

但只要我使用用户选择的文件夹,我就会收到异常。我确定异常是 UnauthorizedAccessException 但我需要一个 bunlded exe 在文件夹内解压缩,然后运行命令以在用户选择的文件夹内生成文件。在执行此操作时,我需要解析正在运行的命令行实用程序的输出。


有什么办法吗?


qq_笑_17
浏览 66回答 1
1回答

万千封印

您可以通过“桌面桥”将 Win32 应用程序打包到 UWP 应用程序包中,然后使用 FullTrustProcessLauncher 运行并通过应用程序服务与其通信。
打开App,查看更多内容
随时随地看视频慕课网APP