It sounds like you’re encountering issues with triggering your scheduled script based on user-related events in Windows 11 Home. Let's break down the problem and explore potential solutions:
1. Understanding Event Logging in Windows 11 Home
Windows 11 Home has limitations compared to Pro editions, especially regarding advanced auditing and event logging. By default, certain security events (like Event IDs 4800 and 4801) may not be logged unless explicitly enabled. This can prevent triggers based on these events from firing.
2. Verify Available Event Logs
First, confirm which events are being logged when you switch users:
-
Open Event Viewer:
- Press
Win + X and select Event Viewer.
-
Navigate to Security Logs:
- Go to Windows Logs > Security.
-
Check for Relevant Events:
- Logon Events: Look for Event ID 4624 (An account was successfully logged on) and Event ID 4634 (An account was logged off).
- Session Switch Events: These might not always be present, especially on Home editions.
If you see these logon/logoff events when switching users, you can use them as triggers.
3. Setting Up Task Scheduler with Logon/Logoff Events
Here’s how to set up your Task Scheduler to trigger on logon or logoff events:
-
Open Task Scheduler:
- Press
Win + S, type Task Scheduler, and open it.
-
Create a New Task:
- Click Action > Create Task.
-
General Tab:
- Provide a name for your task.
- Check Run whether user is logged on or not.
- Check Run with highest privileges.
-
Triggers Tab:
- Click New.
- From the Begin the task dropdown, select On an event.
- Settings:
- Log: Select Security.
- Source: Leave blank or specify if known.
- Event ID: Enter
4624 for logon or 4634 for logoff.
- Click OK.
-
Actions Tab:
- Click New.
- Action: Select Start a program.
- Program/script: Browse to your script or enter the path.
- Click OK.
-
Conditions and Settings Tabs:
- Adjust any additional settings as needed (e.g., only run if on AC power).
-
Finalize:
- Click OK and enter your credentials if prompted.
4. Enabling Additional Auditing (If Necessary)
If you need to log specific events like workstation lock/unlock (4800/4801), you may need to enable auditing via the registry since Windows 11 Home lacks the Local Security Policy editor.
Warning: Editing the registry can be risky. Proceed with caution and back up your registry first.
-
Open Registry Editor:
- Press
Win + R, type regedit, and press Enter.
-
Navigate to:
HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Audit
-
Create/Modify Entries:
- Create DWORD values for the events you want to audit (e.g.,
AuditLock and AuditUnlock).
- Set their values to
1 to enable.
-
Restart Your Computer:
- For changes to take effect.
Note: The exact registry keys can vary, and improper changes can affect system stability. It might be easier to rely on logon/logoff events if possible.
5. Alternative Triggers and Methods
If event-based triggers aren’t reliable, consider these alternatives:
6. Verify Task Permissions and Context
Ensure that:
7. Testing Your Setup
After configuring, test the triggers:
-
Log On/Log Off:
- Switch users and verify if the script runs as expected.
-
Check Task Scheduler History:
- Enable All Tasks History in Task Scheduler.
- Look for any errors or confirmations that the task was triggered.
-
Review Event Viewer:
- Ensure the relevant events are logged when you perform actions like logging in or out.
Conclusion
By leveraging logon and logoff events (like Event IDs 4624 and 4634) and ensuring that these events are properly logged, you can set up reliable triggers for your scheduled script. If you require more specific triggers (like workstation lock/unlock), you may need to enable additional auditing through the registry or use alternative methods such as custom monitoring scripts.
If you continue to face issues, double-check your Task Scheduler configurations, script permissions, and ensure that the events you’re targeting are indeed being logged on your system.
References:
Feel free to provide more details if you encounter specific errors or need further assistance!