I would like to initialize new user account on Windows 10 without login out from admin and login in again to user. Now I create new account with following command:
net user "username" "password" /add
Next I run some program with command that should load user profile:
C:> runas /profile /user:user program.exe
However it is not equivalent to the logging as this user. Environment and some folders structures are not prepared without actual logging in. Is there any way to do this?
2 Answers
The system creates a user profile the first time that a user logs on to a computer. At subsequent logons, the system loads the user's profile, and then other system components configure the user's environment according to the information in the profile.
Then you can't initiative user profile without logging in. Quoted from (v=vs.85)
It IS possible to do this via command line. Though, you'll need to use a system dll instead of plain cmd commands. I found the solution with the help of this answer from serverfault. Here is how to do it:
Download the powerShell-Script from this GitHub site. This script is basically a PowerShell wrapper to use the functionality of
userenv.dll.Save the script in
C:\your\favorite\directoryand renameuser-profile.psm1touser-profile.ps1to easily make it run with PowerShell (*.psm1 is not configured to run in PowerShell by default).Start a PowerShell in elevated mode (as administrator) an navigate to
C:\your\favorite\directory.Run the following two lines in PowerShell (the first line makes the function
Create-NewProfileinuser-profile.ps1available, the second line does the actual work):. "C:\your\favorite\directory\user-profile.ps1" Create-NewProfile -Username testuser -Password start123