How to start a Process from a Win 8 App?

回眸只為那壹抹淺笑 提交于 2019-12-18 08:49:23

问题


I can’t find System.Diagnostics.Process to start a new process. I guess this is on purpose. But is there a other way? Is this even possible?


回答1:


You can use this reference on Windows 8 Metro application : How to Start a external Program from Metro App. All the Metro-style applications work in the highly sand boxed environment and there is no way to directly start an external application.

You can try using Launcher class

  1. Launcher.LaunchFileAsync

    // Path to the file in the app package to launch
    string exeFile = @"C:\Program Files (x86)\App.exe";
    
    var file = await Windows.ApplicationModel.Package.Current.InstalledLocation
                            .GetFileAsync(exeFile);
    
    if (file != null)
    {
        // Set the option to show the picker
        var options = new Windows.System.LauncherOptions();
        options.DisplayApplicationPicker = true;
    
        // Launch the retrieved file
        bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
        if (success)
        {
           // File launched
        }
        else
        {
           // File launching failed
        }
    }
    
  2. Launcher.LaunchUriAsync

Reference: Can I use Windows.System.Launcher.LauncherDefaultProgram(Uri) to invoke another metro style app?




回答2:


Looks like it’s not possible to open any non-metro processes. You can open URLs or Files like *.txt, but not *.cmd or *.exe.

If there is a Custom File Association you could possibly(I haven’t try this) start a process by opening an empty file with your custom filename extension. But you can’t edit the registry to add the association from your app.
So there are no App-Only ways to do this (except not yet discovered hacks ;) ).



来源:https://stackoverflow.com/questions/13563559/how-to-start-a-process-from-a-win-8-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!