Build a user’s profile directory on creation in batch

batchwindowswindows 7

I have a batch script that I use when I set up new Windows 7 PCs that creates a user based on a variable, creates a folder on their desktop, then shares it:

@echo off

SET /p unitnumber="Enter unit number: "

net user unit%unitnumber% password /add /expire:never

MD "C:/Users/unit%unitnumber%/Desktop/Accounting #%unitnumber%"

runas /user:administrator "net share "Accounting#%unitnumber%"="C:/Users/unit%unitnumber%/Desktop/Accounting#%unitnumber""

I discovered that the share that is created is overwritten when the newly created user first logs on, because Windows creates builds their profile directory at that time.

Is there any way to initiate a build of a user's profile directory in the batch file just after creating the it? The only thing that looks useful is the /homedir:pathname switch for the net user command, but I believe that option assumes the directory already exists.

I'd be willing to use whatever to get this done as long as I can incorporate/launch it from the batch.

Any suggestions?

Best Answer

When a new user makes a login for the first time usually the directory c:\Users\Default is copied to the directory with the name of the user. I think that must be enough to build into your batch script.

Related Question