c# - Windows activates task before user logon although trigger is set as "At log on" - Stack Overflow

I want my Win11 c# program to get activated automatically when user logs in.I didn't find anythin

I want my Win11 c# program to get activated automatically when user logs in. I didn't find anything documented for this behavior, but I verified using logs that Windows is running the program very early, without waiting for the user to log on.

In task scheduler I verified:

  1. security options are set with "Run only when user is logged in".
  2. the trigger is set with "At log on"

I tried several machines, and have seen that this is not always the case. On some machines it waits for the login, in others it won't.

I am looking for a way in code to verify that a user is actually logged in.

Already tried:

  1. Reading Session ID:

    int sessionId = Process.GetCurrentProcess().SessionId;

    I always get non-zero, so not useful

  2. using WMI to read UserName - it gets filled with username before I log in.

I'll appreciate any help with this!

I want my Win11 c# program to get activated automatically when user logs in. I didn't find anything documented for this behavior, but I verified using logs that Windows is running the program very early, without waiting for the user to log on.

In task scheduler I verified:

  1. security options are set with "Run only when user is logged in".
  2. the trigger is set with "At log on"

I tried several machines, and have seen that this is not always the case. On some machines it waits for the login, in others it won't.

I am looking for a way in code to verify that a user is actually logged in.

Already tried:

  1. Reading Session ID:

    int sessionId = Process.GetCurrentProcess().SessionId;

    I always get non-zero, so not useful

  2. using WMI to read UserName - it gets filled with username before I log in.

I'll appreciate any help with this!

Share Improve this question asked Mar 4 at 10:29 ishahakishahak 6,7956 gold badges41 silver badges59 bronze badges 12
  • 1 Wouldn't it seem reasonable to first understand the issue before rushing ahead to implement a workaround that's very likely to introduce more problems? – IInspectable Commented Mar 4 at 11:37
  • 2 Add shortcut to Startup folder in Start button. – i486 Commented Mar 4 at 12:20
  • 1 This is possible TBAL. You can check this in next way. Before shutdown - logout from current user. And reboot. I guess will be no auto start your task in this case. And when you reboot with user active - will be autologon and start your task – RbMm Commented Mar 4 at 12:42
  • 1 Does this help? stackoverflow/questions/674628/… – Rufus L Commented Mar 4 at 15:48
  • 1 Trusted Boot Auto-Logon (TBAL) - system save credentials for loged user during shutdown. And on boot read this credentials and do auto logon. And then do lock. As result when you "logon" on startup, you really not logon, but unlock system. Explorer already run at this time, despite you yet on winlogon desktop. Task registered for run on logon, also already started. And how i say, you can simply chech this - if you logoff before shutdown, will be no auto logon on boot next time. If you shutdown without logoff - will be auto logon for last user. So you can view different. – RbMm Commented Mar 5 at 9:23
 |  Show 7 more comments

1 Answer 1

Reset to default 0

Here is an answer to my post, based on comments of @RbMm.

Understanding the Early Task Trigger: The Role of Trusted Boot Auto-Logon (TBAL)

When Windows shuts down without a full logoff, it saves the current user's credentials. On startup, TBAL auto-logs you in (with the session locked), which triggers tasks set for "At log on" immediately.

How TBAL Works

  • Credential Saving:
    Shutting down without logging off saves your credentials.

  • Auto Logon:
    On boot, Windows uses these credentials to log you in and locks the session.

  • Task Triggering:
    Since the environment (including Explorer) starts during auto-logon, tasks scheduled for "At log on" run right away.

Summary

TBAL auto-logs in the last user during boot, triggering "At log on" tasks early. This explains why tasks are activated before a full, manual logon.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745050454a4608354.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信