Previous Up Next

CUIP Tech Site

For Tech Coordinators, NSP-CUIP Techs, and CUIP Staff

Batch User Creation - MD

Batch User Creation HOW-TO -- MD and Home Directories

Instruction

  1. Create the initial Users and Students directories
    1. In the root of the drive that will hold the user accounts, create a directory called 'Users'.
    2. In the new 'Users' directory, create a directory called 'Students'.
  2. Create a worksheet for all the directory creations
    1. In the Excel workbook, create a new worksheet and name it 'homes'.
    2. In cell A1 of sheet 'Homes', enter =CONCATENATE("@echo off")
    3. Calculate the value of G, which is the number of grades in your school (a K - 8 school has 9 grades), minus one if you are doing this after the New Year.
    4. In cell A2 of sheet 'Homes', enter

      =CONCATENATE("if not exist c:\users\students\",YEAR(TODAY())+G-RIGHT(students.csv!E2,1),"\",students.csv!H2," md c:\users\students\",YEAR(TODAY())+G-RIGHT(students.csv!E2,1),"\",students.csv!H2)

      replacing "c:" with the drive letter of the drive where you created 'Users' in (1.1) and G with the value you calculated in (2.3).

    5. Fill this formula for all the students.
  3. Convert the worksheet into a batch file.
    1. From the 'File' menu, select 'Save As...'.
    2. Set the file format to 'Text (OS/2 or MS-DOS)'.
    3. Set the save location to '...\LoginProject\Batch\Students\'
    4. Change the file extension to '.bat'.
    5. Save the file.
    6. Answer 'Yes' or 'Ok' to any prompts Excel gives you.
  4. Run the batch file you've created by either...

Explanation

In the last stage, you created an account for every student in your school on the school's network. One of the best reasons for doing is this is that you can set up the network so that when a student logs on, a new drive appears on the computer they logged onto that will always have whatever they put there. This works because you can write a script that automatically mounts a folder on the local computer that is actually kept on server. In order for this work, you have to actually create that folder; like creating accounts, creating that many folders would be just about too much work. However, in this stage, you'll use excel and the worksheets you already have to create folders for all the students.

The folders you will create will be on one of the hard-drives of the PDC. Usually you want to use the drive with the most space available. So open up this drive, either in the Windows interface or by switching to it in a DOS window. On this drive, create a folder called 'Users' if you don't have one already. Inside 'Users,' create another folder called 'Students' (this way you can repeat this process for the teachers and keep the directories separate, which will make routine maintenance easier in the future.

Now that those directories exist, go back to the Excel workbook and create a new sheet. Name it 'Homes.' When you're finished making this sheet, you're going to export it into a format that can be run just like an executable program, a '.bat' or "batch" file. In other words, the formula you'll use and fill is just a single DOS command repeated over and over with some variations.

In cell A1 of 'Homes,' enter =CONCATENATE("@echo off"). This guarantees that when you run the file, DOS show the command entered over and over again. Don't worry, though, you'll still be able to see any errors or messages that DOS gives you. This will actually make it easier to spot them.

In cell A2, you're going to enter a very long and complicated formula. This formula will create the students' home directories, which will have the same name as the student's user ID. It will also sort the students' home directories into directories according to the year the student is set to graduate. What the formula does, however, is quite simple: it creates a series of directories in between 'students' and the each student's directory. For example, if Andrew Smith is going to graduate in 2005, the formula will create the directory 'c:\users\students\2005\smitha'. This is a good idea because it makes it easier to manage the plethora of folders that will be made. It looks weird, but believe me, it works.

So, in cell A2, enter

=CONCATENATE("if not exist c:\users\students\",YEAR(TODAY())+G-RIGHT(students.csv!E2,1),"\",students.csv!H2," md c:\users\students\",YEAR(TODAY())+G-RIGHT(students.csv!E2,1),"\",students.csv!H2)

Let me explain: 'if not exist X' tells DOS to check whether not X already exists. If it doesn't, DOS will continue on with the rest of the command. If it does, DOS will just skip it. 'c:\users\student\' should be failry self-explanatory, but make sure to replace 'c:' with the letter of the drive where you want the user folders to go. 'YEAR(TODAY())+G-RIGHT(students.csv!E2,1)' calculates the year the student will graduate based on the grade they are in now*. "\" adds a another slash to separate the year of graduation from the student's UID, which is fetched with 'students.csv!H2'. If the directory that this long, tangled formula names doesn't exist, DOS will execute the 'md' (which is md.exe, a program whose name stands for 'Make Directory') followed by that same tangled formula to make it exist. Once you've typed in the formula, hit ENTER and make sure that the result looks like:

if not exist c:\users\students\2005\SMITHA md c:\users\students\2005\SMITHA

If that's right, use AutoFill to extend this for the rest of the students. Now you should have a worksheet with data in only column A. Like we did in the last stage, we're going to export this sheet into a file that DOS can use. As mentioned above, this file is a '.bat' file, or a list of commands for DOS to execute in order. So choose 'Save As...' from the 'File' menu, set the format to 'Text (MS-DOS)' and the location to the 'Batch' folder inside 'Students' in your 'LoginProject' folder, change to the file extension to '.bat,' and click 'Save.' The file 'homes.bat' should now appear in the '...\Students\Batch\' folder. Run it by double-clicking on it, or, if you want to keep track of any errors it generates, run it from within a DOS window by changing into the '...Students\Batch\' directory, typing in homes.bat and hitting ENTER. Now, if you open up the drive where you wanted the folders, you should see 'Users', and inside of it 'Students', and inside of that a folder for each of the years a student currently enrolled could graduate (without being held back!), and inside each of those, folders with the user ID's of the students who will graduate that year. Congratulations! but there's still more to do.


Next: Batch User Creation - CACLS
Previous: Batch User Creation - ADDUSERS
Up: Batch User Creation - Table of Contents
See also: CUIP Home
See also: CUIP Tech Home
CUIP Tech Site Map(not yet working)

This page is: http://tech.cuip.net/topics/logins/md.html
Author: Ben Buckley, benb@cuip.net
Last updated at 09:11 2005n June 17, 2005.
It has had 777917 visitors.