2

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?

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
try this call instead of ExitWindows
Thank you vary match magicandre1981! WTSDisconnectSession() works great in Kiosk Mode.
1

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

Comments

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

1 Comment

I have only 2 apps running: UWP & console written on C#. ExitWindowsEx does not works properly under assigned access mode.
0

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

try this call instead of ExitWindows

This works for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.