1

I am trying to prepopulate a user's home directory before they log in for the first time. I would like to do this programmically. Right now, I can create a the folder, but when a user logs in, it creates a different one with the domain added to the end. Here is what so far.

@echo off
IF EXIST C:\USERS\%1 GOTO COMPLETE
GOTO FIRSTLOGON

:FIRSTLOGON
:: Create user folder on C:\
mkdir "C:\USERS\%1"
:: copy folder structure from template to new user folder
mkdir "c:\Users\%1\Desktop"
mkdir "c:\Users\%1\Documents"
mkdir "c:\Users\%1\Downloads"
mkdir "c:\Users\%1\Music"
mkdir "c:\Users\%1\Pictures"

:: Set rights on new folder
::: Remove inheritance, grant owner everything and admin everything
icacls "C:\USERS\%1" /inheritance:r /grant DOMAIN\%1:(OI)(CI)F
icacls "C:\USERS\%1" /grant %computername%\Administrator:(OI)(CI)F
GOTO END


:COMPLETE
echo Folder creation complete

:END

However, the folder wont be the user's home directory. I am guessing that I will need to add a registry key with the user's GUID to HKLM > SOFTWARE > Microsoft > Windows NT > CurrentVersion > ProfileList, but unsure how to get the GUID from the username, and if I need to do anything else.

Note: I don't want do change the user's home directory for every computer, just the one that they are logging in.

Loaf
  • 111
  • 1
  • 4
  • Why not just do it at first logon instead of ahead of time? – GregL Mar 07 '17 at 14:39
  • @GregL These are VMs being automatically created per request by a user. It is just a preference that everything is completed while a machine is being provisioned. I don't have any experience at doing things at first login. I'll try searching for more information on that. If you have anything I can start from, it would be appreciated. – Loaf Mar 07 '17 at 15:20
  • 1
    Windows will create the folder for the user when the user first logs on. Let Windows do it's job and get out of it's way. There's no advantage to creating the folder beforehand and as you've seen, it's creating a problem for you, for which you've create a cumbersome workaround. – joeqwerty Mar 07 '17 at 16:36
  • @joeqwerty Are you saying the answer I posted is a cumbersome workaround, and I should go about this another way? Or it would be cumbersome to work around how I was previously going about it. – Loaf Mar 07 '17 at 16:40
  • Kind of both. You can configure the user's home folder on the properties of their user account and Windows will create the folder the first time the user logs in. It also looks like your script is creating folders in the home folder. Are you trying to redirect those folders to the home directory? If so, why not use Folder Redirection for that? – joeqwerty Mar 07 '17 at 16:48
  • 1
    I am unable to edit the properties of their user account. However, their home directory is located in the correct place anyways once they log in. I am also not trying to redirect folders either. I copied code from another script I had so some comments may be misleading. – Loaf Mar 07 '17 at 18:47

1 Answers1

0

What I did to resolve the issue was add a registry key at HKLM > SOFTWARE > Microsoft > Windows > Current Version > Run that ran a script in another location. The scripts main purpose was to create a folder in the users home directory and move a file. If the folder already existed, I just exited the script.

I originally had it in RunOnce, however this would only run for the first any user logged in, and wouldn't run if a different user logged in for the first time.

Loaf
  • 111
  • 1
  • 4