Recognize whether the user is logged in

Heiko 1,261 Reputation points
2024-04-18T15:03:37.3466667+00:00

In Windows 10 and Windows 11, apps that are started automatically at startup are already started before the user has logged in. In Windows 8.1, such automatically launched apps were only started after the user had logged in. At least this is the case on my private notebook.

How can I determine whether the user has already logged in? My app plays audio and I don't want audio to be played before the user has logged in.

When starting the app, I check whether there is a 'consent' process, in which case I would only play audio later. Unfortunately, I cannot find such a process and audio is played immediately.

What can I do? My app is a WPF desktop bridge app.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,787 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,657 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,038 questions
{count} votes

Accepted answer
  1. RLWA32 45,701 Reputation points
    2024-04-19T11:14:32.9366667+00:00

    @Heiko, When the system automatically signs-on the user and starts your application there may be a small delay before the session is locked. You can receive notifications when the system locks/unlocks a session. So if your application is notified that the session has been locked it should defer taking action (playing audio) until it receives a notification that the session has been unlocked.

    Notifications can be received by using the SystemEvents.SessionSwitch Event. In the past some have indicated that events have not been fired. Alternative solutions are included in this thread - https://learn.microsoft.com/en-us/answers/questions/1293407/unable-to-capture-sessionswitch-events-in-windows

    Update:

    There is also a Windows API function that you can call using p/invoke that will return whether a session is locked/unlocked. The function is WTSQuerySessionInformationA and the information class to be requested is WTSSessionInfoEx. The returned WTSINFOEXA structure contains a WTSINFOEX_LEVEL1_A structure whose SessionFlags member indicates locked or unlocked. As with most Windows API functions there is also a "W" variant of the function and related structures for wide character strings (UNICODE).

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Kyle Jordan 0 Reputation points
    2024-04-18T16:45:20.2466667+00:00

    Heiko,

    As an experiment can you have the test PC check for the following:

    Go to Settings -> Accounts -> Sign-in Options

    And check for the setting regarding "Use my sign-in info to automatically finish setting up after an update"

    If enabled, disable and restart the device and see if the application still initiates startup during the login screen.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.