c# - 使用 Metro 风格应用程序启动桌面应用程序

标签 c# windows windows-8 microsoft-metro

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

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

最佳答案

如果您只是想运行一个桌面应用程序,如(记事本、写字板、Internet Explorer 等),请查看 Process MethodsProcessStartInfo 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);
}

On Windows 8 Metro application i discovered this: 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 to use Launcher class – depends on your need it may provide you a feasible solution.

检查这个:
Can I use Windows.System.Launcher.LauncherDefaultProgram(Uri) to invoke another metro style app?

引用: How to launch a Desktop app from within a Metro app?

Metro IE is a special app. You cannot invoke an executable from Metro style apps.

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

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
    }
}

关于c# - 使用 Metro 风格应用程序启动桌面应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9527644/

相关文章:

C# WInForms TextBox DataBinding 如果绑定(bind)属性更改则刷新 TetxtBox.Text

c# - Xamarin Studio Storyboard​​空白

python - 在 Python 中使用 argparse - 和默认文件关联

mysql - Google App Engine 中的本地 MySQL

javascript - 如何检测屏幕是否对触摸敏感?

windows-8 - 如何通过 CLI 或 AHK 在 Windows 8 中打开 "Devices and Printers"控制面板?

c# - 从外部 namespace 隐藏函数

c# - SQL父子查询不工作

java - 解决Tomcat中的Bind异常

c# - 如何复制 Win8 metro File Picker UI