net users /add name password
And to add it to administrators use
net localgroup administrators /add name
For example, to add user test
with password 123456789
net users /add test 123456789
and to add test
to administrators
net localgroup administrators /add test
Note that this has to be run in administrator cmd and creates local accounts.
For more help run net users /?
or help net users
in cmd.
To do this in powershell, you could also do this:
New-LocalUser -Name "Name" -Password "Password" -AccountNeverExpires -FullName "NameName"
This will create a new user account that doesn't expire with the name Name
password Password
and full name (file explorer stuff and abbreviations) NameName
. Also requires administrators.
These examples will initialize the new user as you can see by checking net users
again in powershell or cmd. These will also already create the new user directories.
Your issue is that you are attempting to start the program as that user's environment which has not been setup so to run as that user simply use
runas /env /profile /user:user program.exe
With the added /env
switch
See runas /?
/env to use current environment instead of user's.
If I create user test
with
net users /add test 123456789
You can see that they will be in the results of the net users
query and net localgroup users
query. You will also see that their user folder will have been initialized
cd %homepath%\..
dir
Volume in drive C is Local Disk
Volume Serial Number is 1234-ABCD
Directory of C:\Users
06/20/2020 10:05 PM <DIR> .
06/20/2020 10:05 PM <DIR> ..
06/18/2020 01:15 PM <DIR> Neko
03/14/2020 09:16 PM <DIR> Public
06/20/2020 10:05 PM <DIR> test
Something must have to run in that user before it becomes truly initialized.
See https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1, https://ss64.com/nt/net-useradmin.html, get-help New-LocalUser -full
in powershell, net user /?
and runas /?
in cmd.