Run as Different User on Start in Windows
To run a program as a different user when Windows starts, you need to create a scheduled task that triggers at logon and uses the “Run whether user is logged on or not” option with the target user’s credentials. This article explains the exact steps, the underlying mechanism, and common pitfalls so you can set it up reliably.
Why Windows Doesn’t Have a Simple Startup Setting for This
The Startup folder and the registry Run key both launch programs in the context of the currently logged-on user. They cannot specify a different account. The only built-in mechanism that supports running a process under alternate credentials at startup is Task Scheduler, which has been part of Windows since Windows 7 (and remains in Windows 10 and 11).
Another approach is to use a third-party utility that wraps the command line with runas or a similar tool, but Task Scheduler is the native, supported method and works without extra software.
How Task Scheduler Handles Alternate Credentials
When you create a scheduled task with the trigger “At log on” and set the task to run as a different user, Windows stores the credentials securely (encrypted) and starts the task when the specified logon event occurs. The task can be configured to run whether the target user is logged on or not, which means the process runs in a separate session (session 0) unless you choose the interactive option.
If the program needs to show a window or interact with the desktop, you must select “Run only when user is logged on” and ensure the user has an active session. Otherwise, the process runs in the background without a visible UI.
Step-by-Step: Create a Scheduled Task to Run as Another User at Logon
- Press Win + R, type
taskschd.msc, and press Enter to open Task Scheduler. - In the right-hand pane, click Create Task… (not “Create Basic Task”).
- On the General tab:
- Give the task a name (e.g., “Start App as User2”).
- Select Run whether user is logged on or not if you want it to run in the background, or Run only when user is logged on if it needs a visible window.
- Check Run with highest privileges only if the program requires administrator rights.
- On the Triggers tab, click New…:
- Set Begin the task to At log on.
- Choose Any user or a specific user from the drop-down.
- On the Actions tab, click New…:
- Set Action to Start a program.
- Browse to the program’s executable (e.g.,
C:\Program Files\MyApp\app.exe). - Add any arguments in the Add arguments field.
- On the Conditions tab, uncheck Start the task only if the computer is on AC power if you want it to run on battery.
- On the Settings tab, you can enable Run task as soon as possible after a scheduled start is missed to handle delayed logons.
- Click OK. When prompted, enter the password for the user account under which the task should run (the target user).
After saving, the task will run every time that user logs on (or any user, depending on your trigger choice).
Choosing Between “Run Only When User Is Logged On” vs. “Run Whether User Is Logged On or Not”
The main decision is whether the program needs to interact with the desktop. If it’s a GUI application (like a chat client or a sync tool), you must select Run only when user is logged on so it appears on the screen. If it’s a background service-like process (like a backup script or a server), you can choose Run whether user is logged on or not and it will run even if the user never logs in.
Note that when you choose “Run whether user is logged on or not”, the process runs in a non-interactive session, and any attempt to show a window will fail silently. Some programs might crash if they expect a desktop.
Common Problems and How to Fix Them
- Task doesn’t start at all: Check that the trigger is set to “At log on” and that the user account has the right to log on as a batch job (it usually does by default). Also verify the task’s status in the Task Scheduler library.
- Program runs but no window appears: This happens when you chose “Run whether user is logged on or not”. Switch to “Run only when user is logged on”.
- Password prompt appears every time: The task stores the password at creation, but if the password changes, you must update the task. Right-click the task and select “Properties” to re-enter the password.
- Program runs with the wrong user: Double-check the task’s “Run as” user in the General tab. Also make sure the trigger is not set to a specific user that differs from the target.
- Task runs but exits immediately: Some programs need the working directory set. In the Action, set “Start in” to the folder containing the executable.
Alternatives to Task Scheduler
If you prefer a lighter solution, you can use the built-in runas command in a startup script, but it requires the password to be entered manually each time (unless you use a saved credential via cmdkey, which is not recommended for security). Third-party tools like AutoHotkey or dedicated launchers can also do this, but they add complexity and may trigger antivirus warnings.
Another option is to create a shortcut with runas /user:DOMAIN\User "C:\path\app.exe" and place it in the Startup folder, but you’ll be prompted for the password every time, which defeats the purpose of automatic startup.
Security and Safety Considerations
Storing a password in a scheduled task is risky because it’s stored in a reversible form (though encrypted with the machine’s key). Anyone with administrative access to the machine can extract it. Therefore, use this method only on trusted, single-user machines, and avoid using domain administrator accounts.
Also, be aware that running a program as a different user might cause that program to save files in the target user’s profile, not the current user’s. This can lead to confusion about where data is stored. Always test with a non-critical program first.
Frequently Asked Questions
Can I run a program as Administrator at startup without a password prompt?
Yes, you can create a scheduled task with “Run with highest privileges” and set it to run at logon. Since the task is configured with the admin account’s credentials, it will run elevated without prompting, provided the task is set to “Run whether user is logged on or not” or “Run only when user is logged on” (the latter will show a UAC prompt only if the task itself is not configured to bypass it, but typically it runs without a prompt).
What if the program needs to run before the user logs in?
Use the trigger “At startup” instead of “At log on”. The task will run as soon as Windows boots, before any user logs in. This is useful for services-like programs.
Does this work for Microsoft Store apps?
Generally no. Store apps are sandboxed and cannot be launched with alternate credentials via Task Scheduler. You would need to use the app’s full package name and a different method, which is not straightforward.
Can I use a group policy to run a script as a different user at startup?
Group Policy startup scripts run in the context of the SYSTEM account, not a specific user. To run as a specific user, you’d need to use a scheduled task or a custom service. There is no direct GPO setting for that.
Why does the task run twice when I log in?
This can happen if you have both a trigger at logon and the task is also set to run at startup, or if the task is registered in both the user’s context and the system context. Check the task’s triggers and ensure there is only one.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.