当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - How to open Outlook Calendar from an UWP app with an URL

问题描述:

I looked at this page: https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/launch-default-app

and it seems that I can launch almost every Windows app, but for some reason there is not an option to launch the Calendar.. How to do it? Also, what if I want to launch a x86 program?

网友答案:

but for some reason there is not an option to launch the Calendar.. How to do it?

You can also launch the calendar by URL. Code as follows:

await Launcher.LaunchUriAsync(new Uri("outlookcal:"));

The reason you don't know how to launch is that you didn't find the calendar protocol - "Url:outlookcal". Actually you may find an app protocol by open "Settings->Default Apps->Choose default apps by protocol".

Also, what if I want to launch a x86 program?

For other win32 apps , even uwp apps that are not the default apps , they don't have Url protocol at default, you may need to register a protocol for the app and handle URI activation. Then you can launch it by Launcher class in the same way. More details for how to to please reference Handle URI activation. For example you can register Url for a WPF project as follows:

private void InstallProtocol_Click(object sender, RoutedEventArgs e)
{
    using (var hkcr = Registry.ClassesRoot)
    {
        if (hkcr.GetSubKeyNames().Contains(SchemeName.Text))
        {
            MessageBox.Show(string.Format("Looks like {0} is already installed.", SchemeName.Text));
            return;
        }

        using (var schemeKey = hkcr.CreateSubKey(SchemeName.Text))
        {
            //[HKEY_CLASSES_ROOT\com.aruntalkstech.wpftarget]
            //@="Url:WPF Target Protocol"
            //"URL Protocol"=""
            //"UseOriginalUrlEncoding"=dword:00000001
            schemeKey.SetValue(string.Empty, "Url: WPF Target Protocol");
            schemeKey.SetValue("URL Protocol", string.Empty);
            schemeKey.SetValue("UseOriginalUrlEncoding", 1, RegistryValueKind.DWord);

            //[HKEY_CLASSES_ROOT\com.aruntalkstech.wpf\shell]
            using (var shellKey = schemeKey.CreateSubKey("shell"))
            {
                //[HKEY_CLASSES_ROOT\com.aruntalkstech.wpf\shell\open]
                using (var openKey = shellKey.CreateSubKey("open"))
                {
                    //[HKEY_CLASSES_ROOT\com.aruntalkstech.wpf\shell\open\command]
                    using (var commandKey = openKey.CreateSubKey("command"))
                    {
                        //@="C:\\github\\SampleCode\\UniversalAppLaunchingWPFApp\\WPFProtocolHandler\\bin\\Debug\\WPFProtocolHandler.exe \"%1\""
                        commandKey.SetValue(string.Empty, Assembly.GetExecutingAssembly().Location + " %1");
                        commandKey.Close();
                    }
                    openKey.Close();
                }
                shellKey.Close();
            }
            schemeKey.Close();
        }
        hkcr.Close();
    }

    MessageBox.Show(string.Format("Custom scheme {0}: installed.", SchemeName.Text));
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: