简体   繁体   English

Process.Start() 在 UWP 中打开 exe 文件没有任何问题

[英]Process.Start() Open exe file nothing hapen in UWP

no Error just nothing happen and file target still there in my path没有错误只是什么也没发生,文件目标仍然在我的路径中

public void keyboard(){

    ProcessStartInfo touchkey = new ProcessStartInfo(@"C:\Program 
    Files\Common Files\microsoft shared\ink\TabTip.exe");
    touchkey.WorkingDirectory = @"C:\";
    touchkey.WindowStyle = ProcessWindowStyle.Hidden;
    Process.Start(touchkey);
 } 

Update更新

The suggested solution threw a `UnauthorizedAccessException`:

var path = @"ms-appx://C:/Program Files/Common Files/microsoft 
shared/ink/TabTip.exe";
var file = await 

Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(path); Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(path); await Windows.System.Launcher.LaunchFileAsync(file);等待 Windows.System.Launcher.LaunchFileAsync(文件);

Update2更新2

I try to use FullTrustProcessLauncher it's work fine but like code before Keyboard tabtip.exe not show I dont know what should I do我尝试使用 FullTrustProcessLauncher 它工作正常,但就像键盘 tabtip.exe 之前的代码不显示我不知道我应该做什么

   await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
      FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();

     });

Without TabTip.exe 没有TabTip.exe

I recognize you are trying to show the on-screen keyboard judging by the path of the exe . 我知道您正在尝试根据exe的路径显示屏幕键盘。 I suggest a better approach would be to trigger the new touch-enabled keyboard which is easily possible without additional hassle from UWP with InputPane API : 我建议一种更好的方法是触发新的启用触摸的键盘,而无需使用InputPane API从UWP进行额外的麻烦,就可以轻松实现这一点:

var pane = InputPane.GetForCurrentView();
pane.TryShow();

With TabTip.exe 使用TabTip.exe

If you prefer the older on-screen keyboard for some reason, you have two problems with your existing code. 如果出于某种原因而更喜欢旧的屏幕键盘,则现有代码有两个问题。

Firstly, ms-appx: scheme is used to refer to files at the application installation path. 首先,使用ms-appx:方案来引用应用程序安装路径中的文件。 The path you require is an absolute path, so you can't use it there. 您所需的路径是绝对路径,因此您不能在那里使用它。

Secondly, as this is an arbitrary path on the hard drive, you don't have access to it directly (as UWP apps run in a sandbox and can't access the filesystem directly for security reasons). 其次,由于这是硬盘驱动器上的任意路径,因此您无权直接访问它(因为UWP应用程序在沙箱中运行,并且出于安全原因无法直接访问文件系统)。 To access the file, you will need to declare the broadFileSystemAccess capability, which will then allow you to initialize the StorageFile instance. 要访问文件,您将需要声明broadFileSystemAccess功能,该功能随后将允许您初始化StorageFile实例。 You can check for example this SO question to learn how to do just that. 例如,您可以检查此SO问题以了解如何做到这一点。

Note: I don't have my VS PC around so I can't say for sure if this will allow you to launch the executable or not, as that seems like an additional permission which may not be granted. 注意:我没有VS PC,所以我不能确定这是否允许您启动可执行文件,因为这似乎是额外的权限,可能无法授予该权限。 In case this fails, I strongly recommend the first solution. 万一失败,我强烈建议第一个解决方案。

UWP applications are sandboxed and cannot launch other processes directly due to security restrictions. 由于安全限制,UWP应用程序是沙盒式的,无法直接启动其他进程。

The only way to launch other applications is if those applications have a URI registered, or an application is a default handler for a particular file type. 启动其他应用程序的唯一方法是,如果这些应用程序注册了URI,或者某个应用程序是特定文件类型的默认处理程序。

In those instances, you can use methods such as LaunchUriAsync or LaunchFileAsync 在这些情况下,可以使用诸如LaunchUriAsyncLaunchFileAsync

确保已编辑清单文件,并在应用程序中添加了用于完全信任过程的扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM