4

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?

3 Answers 3

0

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 https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/bb776892(v=vs.85)

1

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:

  1. Download the powerShell-Script from this GitHub site. This script is basically a PowerShell wrapper to use the functionality of userenv.dll.

  2. Save the script in C:\your\favorite\directory and rename user-profile.psm1 to user-profile.ps1 to easily make it run with PowerShell (*.psm1 is not configured to run in PowerShell by default).

  3. Start a PowerShell in elevated mode (as administrator) an navigate to C:\your\favorite\directory.

  4. Run the following two lines in PowerShell (the first line makes the function Create-NewProfile in user-profile.ps1 available, the second line does the actual work):

    . "C:\your\favorite\directory\user-profile.ps1"
    Create-NewProfile -Username testuser -Password start123
    
0

If I understand the question correctly. If the intention is to initialize the folder structure for certain user - C:\Users\<some_user> it is enough to invoke this command (either from cmd or powershell)

start powershell -credential ""

You will be asked for credential. If credentials are ok new console will show and the folders will be added.

Call whoami to check if the new console is started with the desired user.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .