有没有方法可以在Windows 8的Metro样式应用程序中启动桌面应用程序?我想创建一些简单的快捷方式来替换开始屏幕上不协调的桌面图标。
我只需要非常简单的东西,最好是用C#编写的,在应用程序加载时就能打开一个应用程序。我打算为一些游戏、Photoshop等制作这些快捷方式,而不是我自己制作的任何东西。它们也只是供个人使用,所以我可以使用直接路径到应用程序,比如 "C:\Program Files (x86)\Steam\steamapps\common\Skyrim\TESV.exe"
有没有方法可以在Windows 8的Metro样式应用程序中启动桌面应用程序?我想创建一些简单的快捷方式来替换开始屏幕上不协调的桌面图标。
我只需要非常简单的东西,最好是用C#编写的,在应用程序加载时就能打开一个应用程序。我打算为一些游戏、Photoshop等制作这些快捷方式,而不是我自己制作的任何东西。它们也只是供个人使用,所以我可以使用直接路径到应用程序,比如 "C:\Program Files (x86)\Steam\steamapps\common\Skyrim\TESV.exe"
如果您只想运行桌面应用程序,如(记事本、写字板、Internet Explorer等),那么请参阅进程方法和ProcessStartInfo类
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 App启动外部程序。所有的 Metro样式应用程序都在高度沙箱环境中工作,没有办法直接启动一个外部应用程序。你可以尝试使用Launcher类 - 根据您的需要,它可能为您提供可行的解决方案。
检查这个:// 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方案,然后执行实际的程序启动。
我喜欢简单的东西,所以我的解决方案是使用这个:
Process.Start("explorer", "shell:AppsFolder\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe!App")
这将启动随着周年更新一起推出的“新”便笺,但它适用于我测试过的所有其他“Metro”应用程序。 要查找Metro应用程序的名称,您必须在Windows资源管理器中使用AppUserModelId列在shell:appsfolder中找到它。
Windows.System.Launcher
类完成此操作,具体使用LaunchUriAsync
方法。 此方法已在下面的回复中给出。 - Pavel Minaev