how to sign out from windows 10 program in uwp?

2019-07-24 17:06发布

问题:

how to log off(sign out) windows 10 using uwp? I have do in win-forms but codes are not working in uwp.

     [DllImport("user32.dll")]
        public static extern int ExitWindowsEx(int operationFlag, int rationReason);

  private void button_Click(object sender, RoutedEventArgs e)
        {
            //Application.Current.Exit();

            ExitWindowsEx(0, 0);
        }

回答1:

In non-UWP programme You can create a new process and run

%windir%\System32\shutdown.exe /l /t 0

But this is not available to UWP programmes. Check out the Stack Overflow link here for another take on this problem. But it looks like you are out of luck.



回答2:

As i see your code above , you are actually closing the application. In UWP , Application works on states like Activated, Running, Suspended or Exited If you want to log out from the application , it means that you would like to wipe of all user data and his Navigation History.

Make A function that clears the NavigationTrace and once the NavigationEntry is cleared , navigate the user to the login screen/home page