【问题标题】:C# launching an external app with metro apiC# 使用 Metro api 启动外部应用程序
【发布时间】:2013-05-20 13:32:02
【问题描述】:

我正在尝试开发一个应用程序,该应用程序使用启动器类从 Metro 应用程序启动常规 .exe 应用程序。 MSDN 提供了一个示例here,stackoverflow 示例是here

问题是我的地铁即使文件在那里也会出现“找不到文件”的错误。我也尝试将文件放在其他驱动器上,但问题仍然存在

这是我的代码示例

// Path to the file in the app package to launch
string imageFile = @"E:\App.exe"; 

var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile); 

/* 上述行中的错误。它说找不到文件 文件名、目录名或卷标语法不正确。 (HRESULT 异常:0x8007007B)*/

if (file != null)
{
    // Launch the retrieved file
    var success = await Windows.System.Launcher.LaunchFileAsync(file);

    if (success)
    {
        // File launched

    }
    else
    {
        // File launch failed
    }
}
else
{
    // Could not find file
}

【问题讨论】:

    标签: c#


    【解决方案1】:

    LaunchFileAsync 用于在其默认程序中启动文件。

    http://msdn.microsoft.com/library/windows/apps/Hh701461

    我不相信它会与 .exe 一起使用

    正确的用法是这样的:

    LaunchFileAsync("images\\picturesofcats.png"); 
    

    这会在您的默认图片查看器中打开一张猫的图片。

    由于沙盒和 .exe 没有默认打开程序,这不适用于 .exe。

    有一些技巧可以解决这个问题,请参阅:Launching a Desktop Application with a Metro-style app

    通常,您正在与 Windows 8 的设计背道而驰,因此您可能需要重新考虑您的方法。

    【讨论】:

    猜你喜欢
    • 2012-08-10
    • 2011-08-03
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    相关资源
    最近更新 更多