2016-05-18 128 views
0

我需要在c#中運行Windows 10的默認相機應用程序。 我試過不同的方法,如:從桌面應用程序運行Windows 10的相機應用程序

process.start("camera.exe"): 
ms-camera:// 
microsoft.windows.camera 

但都失敗了。

這不是一個商店應用程序,所以我不能使用「launch URI」方法。

+0

你能在 「所有失敗」 的詳細點嗎?具體發生了什麼? –

+0

也許有這樣的解釋:https://msdn.microsoft.com/windows/uwp/audio-video-camera/index – CathalMF

+0

你把camera.exe的完整路徑? – BugFinder

回答

4

使用此啓動相機應用:

Process.Start("microsoft.windows.camera:"); 
+0

有沒有使用物理相機的任何相機模擬?我的筆記本電腦上沒有安裝usb cam或cam。因此,我想知道是否有任何相機模擬可以用作UWP應用程序的物理相機? – gayan1991

0

相機應用是通用的Windows應用程序,所以你不能簡單地執行* .exe文件。使用Nasreddine所示的註冊協議或通過IApplicationActivationManager這種方法。

this answer

public enum ActivateOptions 
{ 
    None = 0x00000000, // No flags set 
    DesignMode = 0x00000001, // The application is being activated for design mode, and thus will not be able to 
           // to create an immersive window. Window creation must be done by design tools which 
           // load the necessary components by communicating with a designer-specified service on 
           // the site chain established on the activation manager. The splash screen normally 
           // shown when an application is activated will also not appear. Most activations 
           // will not use this flag. 
    NoErrorUI = 0x00000002, // Do not show an error dialog if the app fails to activate.         
    NoSplashScreen = 0x00000004, // Do not show the splash screen when activating the app. 
} 

[ComImport, Guid("2e941141-7f97-4756-ba1d-9decde894a3d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 
interface IApplicationActivationManager 
{ 
    // Activates the specified immersive application for the "Launch" contract, passing the provided arguments 
    // string into the application. Callers can obtain the process Id of the application instance fulfilling this contract. 
    IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId); 
    IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId); 
    IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId); 
} 

[ComImport, Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]//Application Activation Manager 
class ApplicationActivationManager : IApplicationActivationManager 
{ 
    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)/*, PreserveSig*/] 
    public extern IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId); 
    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] 
    public extern IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId); 
    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] 
    public extern IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId); 
} 

使用源代碼,然後通過其AppUserModelID Microsoft.WindowsCamera_8wekyb3d8bbwe!App啓動相機應用:

private void button3_Click(object sender, EventArgs e) 
{ 
    ApplicationActivationManager appActiveManager = new ApplicationActivationManager(); 
    uint pid; 
    appActiveManager.ActivateApplication("Microsoft.WindowsCamera_8wekyb3d8bbwe!App", null, ActivateOptions.None, out pid); 
} 
+0

我試過兩種方法,但都失敗 第一種方法顯示彈出窗口,以在窗口存儲中查找新應用程序 第二種方法發送異常 –

+0

我已經在Windows 10上成功測試了這兩種方法。也許您已卸載計算機上的相機應用程序。您可以從計算機上的Windows 10的開始菜單啓動相機應用程序嗎? – NineBerry

+0

我可以從菜單啓動它。 你可以請檢閱你的答案。 –

相關問題