使用Metro风格的应用程序启动桌面应用程序

本文关键字:应用程序 启动 桌面 Metro 风格 使用 | 更新日期: 2023-09-27 18:26:28

有没有办法在Windows 8上从Metro风格的应用程序启动桌面应用程序?我正在尝试创建一些桌面应用程序的简单快捷方式,以替换开始屏幕上看起来不合适的桌面图标。

我只需要一些超级简单的东西,最好是C#,在应用程序加载后立即打开应用程序。我正计划为一些游戏、photoshop等制作这些快捷方式,而不是我自己制作的任何东西。它们也只是供个人使用,所以我可以使用到"C:'Program Files (x86)'Steam'steamapps'common'Skyrim'TESV.exe" 等应用程序的直接路径

使用Metro风格的应用程序启动桌面应用程序

如果你只是想运行一个桌面应用程序,比如(记事本、写字板、internet explorer等),那么就通过Process Methods和ProcessStartInfo class

try
{
// Start the child process.
    Process p = new Process();
    // Redirect the output stream of the child process.
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.FileName = "C:'Path'To'App.exe";
    p.Start();
}

//实验2

// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
void OpenWithStartInfo()
{
    ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
    startInfo.WindowStyle = ProcessWindowStyle.Minimized;
    Process.Start(startInfo);
    startInfo.Arguments = "www.northwindtraders.com";
    Process.Start(startInfo);
}

在Windows 8 Metro应用程序上,我发现了以下内容:如何启动Metro应用程序的外部程序。

所有Metro风格的应用程序都在高度沙盒中工作环境,并且没有办法直接启动外部应用

你可以尝试使用Launcher类——这取决于你的需要为您提供一个可行的解决方案。

检查此项:
我可以使用Windows.System.Launcher.LauncherDefaultProgram(Uri)调用另一个metro风格的应用程序吗?

参考:如何从Metro应用程序中启动桌面应用程序?

Metro IE是一款特殊的应用程序。无法从Metro样式的应用程序调用可执行文件

试试这个-我还没有测试,但可能会对你有所帮助。。

Launcher.LaunchFileAsync

// Path to the file in the app package to launch
string exeFile = @"C:'Program Files (x86)'Steam'steamapps'common'Skyrim'TESV.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 launch failed
    }
}

我找到了一个适合我的解决方案。我只是在我的应用程序中创建了一个空文本文件,称之为launcher.yourappyouwanttostart,然后用执行它

Windows.System.Launcher.LaunchFileAsync("launcher.yourappyouwanttostart");

在第一次启动时,它会询问您该文件的关联,然后您选择要运行的exe文件,从现在起,每次执行该文件时,您的应用程序都会启动。

我还没有真正尝试过它是否有效,而且它不是一个真正漂亮的解决方案,但我想Metro风格的应用程序可以启动URI。然后,您可以创建一个为自定义URI方案注册的桌面程序,该方案将执行实际的程序启动。

您可以通过单独安装在计算机上托管外部WCF服务,并使用localhost从metro风格的应用程序连接到它。然后你几乎可以做任何事情,包括Process.Start.

我喜欢简单的东西,所以我的解决方案是使用这个:

Process.Start("explorer", "shell:AppsFolder'Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe!App")

这将启动Windows 10周年更新附带的"新"贴纸,但它可以与我测试的所有其他"Metro"应用程序配合使用。要查找metro应用程序的名称,您必须在Windows资源管理器中使用AppUserModelId列在shell:appsfolder中找到它。