Windows 11 sends me an email whenever someone logs in to an account on my PC. If you’re interested in setting up a notification system like this, I’ll walk you through the steps.

Step 1: Create a Script to Send the Email

The first step is to write the script thatsends an automatic emailwhen someone signs in to a user account on your Windows 11 PC. This script contains your email account’s login details and the custom message that you receive when someone has signed to your PC.

This script stores your email password in plaintext. In theory, that is a security vulnerability if someone finds it and starts going through it. If you’re concerned about that security risk, you can create a throwaway email to use for this instead. That way there is no risk of someone gaining access to your real email.

Notepad’s “Save As” window for saving the login email script.

To create the script, access Windows Search (press Windows+S), typeNotepad, and launch the app. In a new document, type the following script:

In the script, in the Email Settings section, replace theSMTPsettings with those that reflect your email account. you may get these details from Gmail, Outlook, or another email provider that you use. In case you’ve enabledtwo-factor authenticationfor your email account, you’ll have to create an app-specific password and use that instead in the SMTP settings section.

Various options highlighted on Task Scheduler’s “Create Task” window.

After you’ve configured the settings in the script, save the script. From Notepad’s menu bar, select File > Save As. On the Save As window, choose the folder in which you want to save the file. Select the “Save as Type” drop-down menu and choose “All Files.” Click the “File Name” field and type something likeSendLoginEmail.ps1. Then, choose “Save.”

Step 2: Create a Task in Task Scheduler

Your email script is ready, and you’ll now use Task Scheduler to run the script each time someone logs in to a user account on your PC.

To do that, open Windows Search (press Windows+S), typeTask Scheduler, and launch the utility. On the right pane, click “Create Task.”

Various options highlighted on Task Scheduler’s “New Trigger” window.

In the General tab, select the “Name” field and type a name for the task. This could be something likeLogin Email Alert. Turn on the “Run Whether User Is Logged On or Not” and “Run With Highest Privileges” options.

From the top bar, open the “Triggers” tab. Click “New” to add a new trigger. Select the “Begin the Task” drop-down menu and choose “At Log On.”

Various options highlighted on Task Scheduler’s “New Action” window.

If you want to get an email alert when any user logs in to your PC, choose “Any User.” To only get an alert when someone logs in to a specific user account, enable “Specific User.” Then, click “Change User” and select the account.

Open the “Actions” tab and click “New” to add a new action. Select the “Action” drop-down menu and choose “Start a Program.” Select the “Program/Script” field and typepowershell.exe. In the “Add Arguments (Optional)” field, type the following. ensure to replace the script path with the path to the script you created earlier.

Various options highlighted on Task Scheduler’s “Edit Action” window.

Select “OK,” enter your admin password, and save the task.

From now on, Windows 11 will automatically send you an email when someone logs in to your PC. In the future, if you don’t want to receive these alerts, right-click your task in Task Scheduler and choose “Delete.”

To quickly find these emails in your inbox, you canset up a label. The script above uses “Login Alert on” as the subject line, which you can use to filter all these emails.

Hide the PowerShell Window on Startup

To send you an email alert when someone logs in to your PC, Windows 11 launches PowerShell for a brief moment. This means anyone logging in to your PC will see that window. If you’d like to hide the window, do the following.

Open Notepad and type the following. Make sure to replace the script path with your script’s path.

From Notepad’s menu bar, select File > Save As. Select the folder in which you want to save the script. Click the “Save as Type” drop-down menu and choose “All Files.” Click the “File Name” field and typeSendLoginEmail.vbs. Then, choose “Save.”

Open Task Scheduler and edit your task. For the action, change “Program/Script” towscript.exe. In the “Add Arguments (Optional)” field, type the following, replacing the path with your script’s path.

And you’re done.

And that’s how you get an email alert when someone accesses your Windows 11 PC. If you want to allow others to use your computer, you can considersetting up a guest account on Windows 11.