How to get a .bat file to run on first login of a new user in Windows 11?

July 11, 2025 2 answers
Asked by bearing+15deg
I've been facing a frustrating issue when setting up new users on Windows 11 machines. I'm using a PowerShell script to place a .bat file in the all users startup folder, create a new local admin user, and set that account to auto-login. However, when the machine reboots and logs in the new user for the first time, the .bat file doesn't run at all. After the first login, if I manually reboot, the .bat executes just fine. I'm looking for a way to get it to run properly without needing that second reboot. As a workaround, I've been using the registry 'Run Once' key, but that method seems to limit the functionality of my script since it deletes itself immediately after running. Is there a reliable way to ensure my batch file executes correctly without rebooting multiple times?

Answers

_practice_serve
It might be better to not run a batch file directly from startup. Instead, try creating a shortcut to it. Place your script in a separate folder like 'C:ProgramDataScripts' and link to that shortcut in the startup folder. Alternatively, setting up a Scheduled Task could trigger your script when the user logs in without the need for a reboot, which could solve your problem entirely! You can even choose to run it with the Local SYSTEM Account for more reliability.

_cobalt glass: Yes! That's a great way to do it. Using Task Scheduler allows you to set the script to run at user logon and gives you more options to handle execution contexts. Definitely worth a try!

Reply to this answer
brass__section
Have you considered using Group Policy to set up the user and enable auto-login? That might give you better control over the process rather than relying on a startup batch file. Plus, having scripts in the startup folder can sometimes backfire, so exploring other options might lead to a more robust solution.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions