【问题标题】:Is it possible to navigate to the lock screen in Windows from a UWP app?是否可以从 UWP 应用导航到 Windows 中的锁定屏幕?
【发布时间】:2016-07-21 22:46:00
【问题描述】:

我有一个 UWP 应用程序(永远不会提交到商店),在这个应用程序中有一个“管理”部分。我想在此部分添加一个按钮,将用户导航到 Windows 锁定屏幕。从那里,用户可以决定以不同的用户身份登录。这可能来自 UWP 应用程序吗?如上所述,此应用不会进入商店,因此不需要通过任何商店要求。

【问题讨论】:

  • 你检查我的答案了吗?有什么问题吗?

标签: uwp lockscreen


【解决方案1】:

如上所述,此应用不会进入商店,因此不需要通过任何商店要求。

由于您的应用不会上传到商店,您可以使用VS2015TemplateBrokeredComponents 在 UWP 应用和传统桌面应用之间架起一座桥梁。这也意味着,目前还没有针对这项工作的 UWP app 可用的 API,但是有基于 Win32 的 API 可以解决这个问题。

要完成这项工作,最好参考Brokered Windows Runtime Components for side-loaded Windows Store apps 开始。

构建这样一个应用程序需要采取的步骤,你可以按照VS2015TemplateBrokeredComponents的简要指导。这里我不会再次列出步骤,我将只粘贴一些您可能需要的代码,例如这里,在Brokered WinRT Component 项目中创建一个“IAppLauncher”接口:

[ComVisible(true)]
public interface IAppLauncher
{
    /// <summary>
    /// Launch desktop application from file name
    /// </summary>
    /// <param name="fileName">target application executable file name</param>
    void Launch(string fileName);

    void LaunchWithArg(string fileName, string arguments);
}

创建一个继承自该接口的“AppLauncher”类:

[ComVisible(true)]
public sealed class AppLauncher : IAppLauncher
{
    /// <summary>
    /// Launch desktop application from file name
    /// </summary>
    /// <param name="fileName">target application executable file name</param>
    public void Launch(string fileName)
    {
        Process.Start(fileName);
    }

    public void LaunchWithArg(string fileName, string arguments)
    {
        Process.Start(fileName, arguments);
    }
}

在构建、注册、引用项目和修改 Manifest 文件后,您可以在 UWP 应用中使用它,例如:

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    new AppLauncher().LaunchWithArg(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 2019-03-14
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多