1

I have console app running in background under Assigned Access (Windows 10's Kiosk Mode). By command from main UWP-app it should logoff current user. I've tried 2 ways to do this:

  • WinAPI function ExitWindowsEx(0, 0)
  • Process.Start("shutdown /l /f")

Both works well if current user has password. But if user has no password, Windows re-login immediately after logout. Is there a way to avoid re-login?

UPDATE: Looks like LockWorkStation does not working too. May be it for security reasons?

FiftiN
  • 740
  • 1
  • 7
  • 27

4 Answers4

2

According to Raymond Chen from Microsoft this is not possible:

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.

In your Client/Server were UWP app send request to a desktop application, approach try the WTSDisconnectSession() call in the desktop application, as suggested here.

magicandre1981
  • 27,895
  • 5
  • 86
  • 127
  • I know it. And I split my app into two: UWP app & Desktop Console App. They communicate over WCF. When user press "Logout" button in UWP-app, it send request to Console app witch executes ```ExitWindowsEx(0, 0)```. Its works fine but not under Assigned Access mode. – FiftiN Dec 14 '17 at 16:09
  • 1
    [try this call](https://stackoverflow.com/a/14467587/1466046) instead of ExitWindows – magicandre1981 Dec 14 '17 at 16:18
  • Thank you vary match magicandre1981! ```WTSDisconnectSession()``` works great in Kiosk Mode. – FiftiN Dec 15 '17 at 19:33
0

Try this

Log off the current user.

ExitWindows(0, 0);
ExitWindowsEx(EWX_LOGOFF, 0);

With User Interaction

The application receives the WM_QUERYENDSESSION message and displays a dialog box asking the whether it is OK to end the session. If the user clicks Yes, the system logs off the user. If the user clicks No, the logoff is canceled.

case WM_QUERYENDSESSION:  
{ 
    int r; 
    r = MessageBox(NULL,(LPCWSTR)L"End the session?",(LPCWSTR)L"WM_QUERYENDSESSION",MB_YESNO);

    // Return TRUE to continue, FALSE to stop. 

    return r == IDYES; 
    break; 
}
Darshit Hedpara
  • 660
  • 6
  • 17
  • I have only 2 apps running: UWP & console written on C#. ```ExitWindowsEx``` does not works properly under assigned access mode. – FiftiN Dec 14 '17 at 15:35
0

Thank you vary much to @magicandre1981 for answer in comments. His answer:

try this call instead of ExitWindows

This works for me.

Emiswelt
  • 3,909
  • 1
  • 38
  • 56
FiftiN
  • 740
  • 1
  • 7
  • 27
0

I actually found this on msdn

It explains how to exit assigned access. Get the LockApplicationHost from current view. If host is null, the app doesn't run under assigned access, so it's been started normally. And then call RequestUnlock() and the Login Screen shows and you can log in with different user.

Windows.ApplicationModel.LockScreen.LockApplicationHost lockHost = Windows.ApplicationModel.LockScreen.LockApplicationHost.GetForCurrentView();

if (lockHost != null)
{
    lockHost.RequestUnlock();
}
Jmie
  • 97
  • 1
  • 12