1

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);
        }
Brody
  • 2,074
  • 1
  • 18
  • 23
Trishit Bera
  • 101
  • 1
  • 9
  • Are you trying to logout of Windows or close the application. I'm not sure Windows will let you log out from an application it is running. – Brody Apr 07 '16 at 06:03
  • yes, i want to log out from WIndows using uwp app.. – Trishit Bera Apr 07 '16 at 06:07
  • give a log out button and clear the stacktrace and then redirect the user to the home page – Apoorv Apr 07 '16 at 07:22
  • No, i want to sign out from my system(windows 10) using uwp app.. – Trishit Bera Apr 07 '16 at 07:33
  • 1
    UWP applications cannot sign users out or lock the workstation. That would result in a denial of service from an app that just locked the workstation in a tight loop. Also, some device families don't support signing out. (How do you sign out of your phone or fitness band?) – Raymond Chen Apr 07 '16 at 23:23

2 Answers2

0

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.

Community
  • 1
  • 1
Brody
  • 2,074
  • 1
  • 18
  • 23
-1

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

Apoorv
  • 2,023
  • 1
  • 19
  • 42