2

I need to just run default camera app of windows 10 in c#. I tried different methods like:

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

But all failed.

It is not a store app so I cannot use "launch URI" method.

NineBerry
  • 26,306
  • 3
  • 62
  • 93
Asim Mehmood
  • 29
  • 1
  • 4

2 Answers2

7

Use this to launch the Camera app:

Process.Start("microsoft.windows.camera:");
Nasreddine
  • 36,610
  • 17
  • 75
  • 94
  • Is there any camera simulation without using physical camera? I do not have a usb cam or a cam installed in my laptop. Therefore, I would like to know is there any camera simulation that could work as a physical camera for a UWP app? – gayan1991 May 24 '16 at 03:37
  • that's cool, even doing it from the command-line works, e.g. start microsoft.windows.camera: – George Birbilis Feb 10 '22 at 08:25
0

The Camera app is a Universal Windows app, so you cannot simply execute an *.exe. Use the registered protocol as shown by Nasreddine or this approach via IApplicationActivationManager.

Use the source code from 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);
}

and then start the camera app via its 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);
}
Community
  • 1
  • 1
NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • I tried both methods but failed both First method shows popup screen to look a new app in window store Second method send exception – Asim Mehmood May 18 '16 at 15:26
  • I have tested both methods successfully on windows 10. Maybe you have uninstalled the camera app on the computer. Can you start the camera app from the start menu in windows 10 on your computer? – NineBerry May 18 '16 at 23:46
  • I can start it from menu . can you please review your answers. – Asim Mehmood May 21 '16 at 11:47
  • Please add Screenshot of the entry in the Startmenü and a screenshot of the running App to the question, so we know wer are talking about the same thing – NineBerry May 21 '16 at 11:58