bemoore
bemoore

Reputation: 94

Getting the directory of a newly created windows user

I have a Windows batch file where I create a user as Administrator called Trainee. Then I want to copy some files into the Desktop folder for the Trainee user.

I need to be able to get the Windows desktop folder of this newly created user and copy some files into it. How do I do this? The %USERPROFILE% only tells me the Administrator user's folder.

REM Create the new user
NET user Trainee <password> /ADD 

Then I copy some files into what I think should be the newly created user, but it keeps changing like adding .000 to trainee or the machine name.

I've tried setting the HOMEDIR and the PROFILEPATH like so

NET user Trainee <password> /ADD /HOMEDIR:<some_path> /PROFILEPATH:<some_path> 

but all this does is sets the path in a DOS prompt for the Trainee user, it doesn't set the Windows path.

... How do I get the Windows home dir for the newly created Trainee user?

I can't use runas as this needs to be completely automatic, not prompting for a password.

Upvotes: 1

Views: 509

Answers (2)

bemoore
bemoore

Reputation: 94

The answer is this can't be done, at least with a batch file. The problem is that the user profile is not yet created, so what I will have to do is set up some sort of a batch script to run after the Trainee user logs and do this setup. Thanks everyone.

I also think the creation of new profiles is due to me copying in files BEFORE anyone has logged in.

Upvotes: 0

Compo
Compo

Reputation: 38654

Despite this question being better suited to Super User, your commands don't appear to be creating an administrator account for Trainee.

To do that you'd need to use, as an administrator:

net user /add Trainee Pa55_W0rd
net localgroup administrators Trainee /add

Also I'd guess that the new user would need to log in such that their directory structure and account setup is carried out. Until then there is nowhere to copy anything to.

Upvotes: 1

Related Questions