Build a user's profile directory on creation in batch

0

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?

Moses

Posted 2013-10-21T21:05:11.697

Reputation: 10 813

Answers

1

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.

noggerl

Posted 2013-10-21T21:05:11.697

Reputation: 1 229

You're right, just watched my Windows installation from linux and didn't recognis that there are multiple symlinks to the directory. On my installation I got Documents and Settings and Dokumente und Einstellungen as it is called on a german installation. And Default User is a symlink to Default. Just an old habbit from Windows XP times... – noggerl – 2013-10-21T22:27:44.270