how to sign out from windows 10 program in uwp?

2019-07-24 17:09发布

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

2条回答
Root(大扎)
2楼-- · 2019-07-24 17:37

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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-07-24 17:52

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

查看更多
登录 后发表回答