user6115111
user6115111

Reputation: 41

Is it possible to navigate to the lock screen in Windows from a UWP app?

I have a UWP app (that will never be submitted to the store), and within this app there is an "admin" section. I would like to add a button to this section that will navigate the user to the Windows lock screen. From there, the user can decide to log-in as a different user. Is this possible from a UWP app? As mentioned above, this app will not be going into the store so it doesn't need to pass any store requirements.

Upvotes: 2

Views: 457

Answers (1)

Grace Feng
Grace Feng

Reputation: 16652

As mentioned above, this app will not be going into the store so it doesn't need to pass any store requirements.

Since your app won't be uploaded to store, you can use VS2015TemplateBrokeredComponents to build a bridge between UWP app and traditional desktop app. This also means, there is no available APIs for UWP app for this work, but there is APIs based on Win32 can solve this problem.

To do this work, it's better to refer to Brokered Windows Runtime Components for side-loaded Windows Store apps to get started.

The step you need to take to build such an app, you can follow the brief guidance of VS2015TemplateBrokeredComponents. Here I WON'T list the steps again, I will paste only some code you may need for this scenario, for example here, in the Brokered WinRT Component project create a "IAppLauncher" interface:

[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);
}

create a "AppLauncher" class inherit from this interface:

[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);
    }
}

After building, registration, referencing to projects and modification the Manifest file, you can use this in your UWP app for example like this:

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

Upvotes: 2

Related Questions