Jump to content

Recommended Posts

Posted

I hate writing scripts or batch files because I always break things. Can anybody help me make a script that makes a folder inside users home directories.

 

For example. The students home folder is C:\students\username on the server. What I need to make is a folder inside the \username folder so,

C:\students\username\newfolder

I have over 500 accounts to do so I was hoping that I could use some sort of %username% type command or wildcard. I've Googled but im all out of Google Fu today. :(

Posted

You could use Group Policy Preference mode, User Configuration to create a folder.

 

Do the users get their home directory mapped as a particular drive? Say it Maps to H:\ you could set the GPP to create H:\new folder

Posted (edited)
I hate writing scripts or batch files because I always break things. Can anybody help me make a script that makes a folder inside users home directories.

 

For example. The students home folder is C:\students\username on the server. What I need to make is a folder inside the \username folder so,

C:\students\username\newfolder

I have over 500 accounts to do so I was hoping that I could use some sort of %username% type command or wildcard. I've Googled but im all out of Google Fu today. :(

 

CLS

::variables

set name=c:\Students\

::commands

md %name%\%username%\nameoffolder

 

add pause if you want it to halt before exiting, else exit.

 

create a .bat and set to run at logon.

 

Should work.

 

:)

 

 

Also, if you find the %username% doesn't work (as it pulls the user of the current process and isnt always correct), then use this:

 

for /f "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq explorer.exe" /FO LIST /V') do if /i "%%a %%b"=="User Name:" set _currdomain_user=%%c

for /f "TOKENS=1,2 DELIMS=\" %%a in ("%_currdomain_user%") do set _currdomain=%%a & set _curruser=%%b

Edited by DT2
Posted
You shouldn't need a 2008 server. GPP's apply to all devices with XP SP3 and above I believe. You should be able to run a Win 7 pc with the RSAT tools installed and this should let you managed these settings :-)
Posted

for /f "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq explorer.exe" /FO LIST /V') do if /i "%%a %%b"=="User Name:" set _currdomain_user=%%c

for /f "TOKENS=1,2 DELIMS=\" %%a in ("%_currdomain_user%") do set _currdomain=%%a & set _curruser=%%b

 

Just the kinda stuff I was hoping to avoid. :D

 

The .bat file sounds promising. If its to run at logon though I'd would need the network map so

set name=h:\domaincontroller\students\%username%\newfolder

md %name%\%username%\nameoffolder

 

Sould that work?

Posted

Yeah, you can just stick net use in there in stead of the %name% variable.

 

net use H: \\server\share\%username%

md H:\newfolder

If H: is already mapped then it's even easier, just omit the net use command.

:)

Posted

Arh I see. Yes H:\ is their home folder.

 

Oh how much easier this would have been if I could have just typed "mkdir c:\students\*\newfolder" where * is the random folder/username. It works on files, why not folders too.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...