2013-05-20 33 views
0

我想开发一个应用程序,从地铁应用程序使用启动类启动一个常规的.exe应用程序。 MSDN提供了一个样本here和一个计算器样本是hereC#启动与地铁api外部应用程序

问题是,我的地铁给出了“找不到文件”的错误,即使文件存在。我试图把文件上的其他驱动器,但问题仍然存在

这里是我的代码示例

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

回答

3

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

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

我不相信它会带有.exe

正确的用法工作是一样的东西:

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

这然后打开猫的图片在默认的图像浏览器。

由于sandboxing,并且因为.exe没有默认的开启器,所以这对于.exe不起作用。

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

一般情况下,你的工作对Windows 8的设计要做到这一点,所以你可能要重新考虑你的方法。

+0

我也试过它在同一个地方的JPG文件,但没有解决 – Umair

+0

尝试使用Windows.Storage? http://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1 – KingCronus

相关问题