c# - 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 在文件夹中解压,然后运行命令以便在用户选择的文件夹中生成文件。这样做时,我需要解析我正在运行的命令行实用程序的输出。
有什么办法吗?
解决方案
您可以通过“桌面桥”将 Win32 应用打包到 UWP 应用包中,然后使用FullTrustProcessLauncher运行并通过应用服务与其通信。这是一个样本。
推荐阅读
- laravel - 为什么自引用下拉菜单不显示任何内容
- jquery - jQuery Datatable - TypeError:settings.aoColumns[column] 未定义,而表格格式正确
- laravel - 使用 laravel 范围避免歧义
- spring - 如何使用 Spring 的 yml 中的属性的键中的变量
- node.js - 用于 nodejs 和 postgresql 的迁移生成器文件工具
- python-3.x - 圣杯包:无法安装依赖项:graphqlclient==0.2.4
- docker - 延迟容器启动
- reactjs - React Redux Connect:未捕获的不变违规:找不到“商店”
- php - 在 Laravel 中使用正确的扩展名重命名文件
- sql - PostgreSQL计算多行之间的差异