Jump to content

My Docs, Class Shared & Shortcut generator


Recommended Posts

Posted

This script is something of an ambitious one for me as it's intended to take the pain out of the somewhat difficult system we have at this school by which children don't move in a linear fashion with their classmates.

 

Basically at some point between years 4 and 6 they are kept in the same class for 2 years. I'm not sure why either but it's the way it's done...

 

 

Anyway I came up with a structure that should allow for the peculiarities of the system so it works something like this:

 

H: has been set in their profiles to:

//server/userdata/Students/Individual/%username%/

 

...but because we wanted to break work into specific years and to provide something of an archive we then want work to go in folders for each academic year under their directory above.

 

The script handles this transparently and as far as the children are concerned they start each year with a clean "My Documents" folder.. In truth all that happens is that the script checks the current date and the childrens "My Documents" folder gets redirected to the appropriate year

 

//server/userdata/Students/Individual/%username%/[academic_year]/

 

eg: ... %username%/2006-07/ => My Documents

 

 

Now where it gets a bit "clever" is that the script automatically creates the relevant folder(s) for that child and if the date is past a certain point in the summer holiday it figures it's a new year and creates the new academic years folder.

 

It gets "better" :)... Because we're not expecting (nor wanting) the teachers to wade through individual profiles to find their class of kids it also creates a folder of shortcuts in the structure:

 

//server/UserData/Staff/Childrens Work/ClassX/[Academic Year]/

 

Again it creates the relevant folder if it's missing and based on the OU (childrens user accounts are in OU's for their current class) that the childs account belongs to, a shortcut to the childs work is then created in the relevant class/[year] folder.

 

This then allows teachers to go through their classes work this year and in previous years... it also makes the job of archiving work, and/or creating a portfolio of work a LOT easier for the poor TA currently tasked with the role.

 

 

 

Ok... that's the description... Problem now is that I'm a PHP coder so vbs is totally new and alien to me... I think I've more or less got it right but I could use some help debugging it and checking my logic... so please see the attached... Comments welcome.. :)

 

 

Oh and just to note.. This is intended as a login script and I'm aware it's likely to create an overhead to the system that I can probably tweak.. but right now a 10 or so second login delay is affordable compared to spending hours sorting this lot manually..

student_folders.vbs

Posted

If anyone is a vbs coder expert or can offer some insight I could use some help at this point..

 

I'm getting an "end expected" error for the end line in the script and can't find the cause...

 

I'd welcome any "read this and learn" references as well as vbs is something I intend to get my teeth into some more

Posted
Do I recognise those UserINOU and ComputerInOU functions from somewhere? :)

Yeah... they were borrowed from other fine resources provided on this forum...

 

.. and once it all works I'll be sure and spread around the credit :)

Posted

Not an expert vbcoder but I can spot "if" and "end if" that don't match:

If fso.FolderExists(scFolLocYr) Then

' Do nothing, share already exists

Else If scFolLoc <> Nothing Then

CreateDirs scFolLocYr

Else

scFolLocYr = Nothing

' Do nothing (not valid group)

End If

 

I think needs to be

 

If fso.FolderExists(scFolLocYr) Then

' Do nothing, share already exists

Else

If scFolLoc <> Nothing Then

CreateDirs scFolLocYr

end if

Else

scFolLocYr = Nothing

' Do nothing (not valid group)

End If

 

- every "if" needs a matching "end if" unless it's all on one line (ie you can do if x=3 then wscript.echo "x=3"

 

I *think* what you're trying to do might be easier expressed as:

 

If not(fso.FolderExists(scFolLocYr)) and scFolLoc <> Nothing Then

CreateDirs scFolLocYr

End If

 

KISS very much applies here - if you can see what's going on in just a few lines then it'll make it much easier to debug! My rule (which I break too often) is that the main flow of a script should fit on a screen; it can call functions and sub-routines and each of them should also fit on a screen if possible.

 

the other thing is to use an editor that makes indenting easy - I use context (http://www.context.cx) which is free and quite good. If you get the indents right then it's easy to spot when you miss end if, next, loop etc.

Posted

Cheers Steve..

 

You made me go away and look up a few things and I think it was actually down to the else if being spaced out rather than elseif which is apparently valid.

 

I take your point re: the simplification which I'll do when I've got it working but more than anything else I needed to see my logic clearly which the original drafts do quite well.

 

Thanks for pointing me in the right direction and as to editor, I know what you mean there, I paid out for UltraEdit Studio which has been invaluable in my PHp coding and pretty good for this too..

 

Thanks again...

 

Martin

Posted

Ok... had a chance to do some debugging and got it to this daft which is version #3 now...

 

 

Going to be giving it a go tomorrow with a single class to see if it does what it should...

 

In the mean time if anyone wants to see if they can spot any problems or suggest improvements... please do.. :)

student_folders_652.vbs

  • 2 weeks later...
Posted

Right...

 

Daft #4 and having finally debugged the thing over the course of the day there's a few things to note with this latest incarnation..

 

1. If the file system hasn't been run before it will take quite a while for the script to create most of the base folders.

 

2. Due to 1. The script has delays built in that keep on checking for the folder to be created before moving on to the next stage..

 

3. This in turn means that login time takes a while...

 

 

All in all though the system will basically run smoothly once the folders have been created at the beginning of the year (or first login)... and I figure it'll be worth creating a seperate script to be run during the summer holidays that essentially runs through the AD and creates all the folders for the existing users... Any new, last minute additions are then covered later on... But that's a whole other story :)

student_folders_717.vbs

Posted

Bugger, bugger, bugger...

 

As part of my deployment with this I was intending to use mandatory profiles to help reduce the load.. Unfortunately this doesn't work as mandatory profiles seem to lock the registry keys my script uses for stuff like "My Documents" to the "User Default" profile..

 

Looking into a resolution for this...

  • 2 months later...
Posted

I need to rewrite the original scripts code as there's a dumb error in there but just quickly ...

 

This new script attached is an admin "run manually" script that allows you to create the folders manually without having to rely on the login script.

 

It parses the LDAP structure (which you need to set) and then creates any missing folders.

 

Useful to run when you've done all your AD user account creations/import/etc....

create_folders_generic.vbs

Posted
this looks really good and i would love to know what to change so i can use it on my network.

I'll get it all updated and with documentation when I've had a chance to fix up the original script (which is just plain pants atm).

 

No sense in just having one without the other eh? ;)

Posted

Ok.. don't hold your breath but after working with this some more I've realised that I neglected to deal with permissions issues (ie: sharing the shared folder between class OU's and a whole lot more.

 

 

So I've been pretty much re-writing the code on this little lot and wouldn't advise anyone to use this right now.

 

 

That said once done the script should do the following:

 

  • Read the OU's contained in a specific OU (eg: ou=classx,ou=classes)
  • Append any ou user containers into a security group for that class
  • Create all the folders required with academic year sub-folders to keep everything organised, shared folders for the whole class
  • set permissions for the class shared folder so the class security group can access it (and the staff security group)
  • Create shortcuts to the childrens individual folders for each year in a staff folder with folders for each class. Making it easy to locate childrens work for a given year.
     
  • Make the bed, cook the dinner and offer bug rubs...

;)

Posted

Right....

 

This is finally something to be happy with.. There's a bit of unexplained behaviour going on (ie: it's trying to access the A: drive for some reason) but this now does what it's supposed to..

 

Feel free to play around with it and note you'll need the xcacls.vbs

 

... and to place it in the same directory as the actual script (or alter the path to xcacls.vbs)

 

I'd appreciate any assistance with the mystery drive A: requests and in getting the error handling to be more specific to ignore the expected errors that might be called (eg: group exists, member exists, etc.. ) and die at those it shouldn't.

 

I've also found that the xcacls.vbs calls will result in a pop up saying extended error reporting is turned off and using cscript as part of the wshell.run just gets you a CMD window so it's a choice of evils there...

 

 

Anyway, comments welcome.. preferably good ones ;) ... but hey :p

Posted

Right... some of this stuff is untested.. but I figure I'll post up the current structure as it's close to being there.

 

I've split the system further so that there's now 3 script files.

 

1. usr_fldr_struc_create_man-eg.vbs

The main script to be run whenever a major update has taken place to student users, classes... and before the new school year starts

 

2. usr_fldr_struc_create_login-eg.vbs

This is part #1 of the login script that deals with any minor updates as part of the login process.. If someone logs in that was added late in the day (ie: joined a class mid term, etc...) then the script will create their individual folders and add them to the relevant security group.

 

3. usr_fldr_map_login.vbs

This is the simplest part of the whole deal and just maps the relevant folders to drive letters as well as redirecting the mydocs to the right place.

 

 

The scripts have notes in them that should explain how it's supposed to work and you'll probably pick bits up from the rest of the thread.

 

What definitely works (for me at least) is part #1 which is the meat of the system. The follow up bits are getting tested and debugged tomorrow..

  • 2 months later...
Posted

Apologies to anyone who tried the last set of scripts but I'm guessing that lack of replies complete with gnashing of teeth, etc... mean't there were few who tried :p

 

There were a few issues with the original set that have since come to light so I spend some time working on them properly using my new VM setup for testing (very useful!).

 

 

Changelog:

  • Fix: containerName (cn) different from sAMusername (account login) failed to create logins
  • Removed: attempt to add users to security group in login script (usr_fldr_create_login.vbs). Relevant permissions not available as users aren't admins.
  • Fix: corrected key => val for my docs and my pictures
  • Fix: missing variable value for shortcut destinations
  • ... plus various other small bug fixes.

 

This has been tested on my test LAN so it should now work properly but a few things to be aware of:

- GPO for pupils needs to be set:

Computer Configuration/Administrative Templates/System/Scripts/Run logon scripts synchronously - TRUE

.. otherwise the map_login will clash with the create_login script.

 

Before you get ANY children to login you will need to run the:

usr_fldr_struc_create_man.vbs

.. script first as an admin on your fileserver. This sets up shared folders, permissions. I've found that for some reason you need to run this twice to get permissions to take (Not sure why).

 

In terms of running the scripts.. Set for your pupils OU as login scripts to run in order:

- usr_fldr_struc_create_login.vbs

- usr_fldr_map_login.vbs

 

 

Comments, as always, welcome.

 

 

Note: -eg postfix in the scripts is just for my own reference. These have generic directory and AD settings.

Posted
I have downloaded all three and it looks really good I do have a problem when i downloaded i cant read two of the scripts.

 

Yeah... think I left them in Nix format...

 

I've got some changes to make and re-upload so I'll sort the formatting issue then.

  • 3 weeks later...
Posted

Ok... Yet another release but this one seems to have resolved most of the bugs and mistakes in the earlier versions

 

'*	$Author: martin $
'*	$Date: 2007-09-26 08:54:49 +0100 (Wed, 26 Sep 2007) $
'*	$Revision: 27 $

 

Changelog:

  • Permissions using XCACLS.vbs now fixed to interactive mode (more info)
  • XCACLS.vbs only used in the man(ual) script as permissions require an admin
  • Shortcuts now include one to the class share folder
  • Security Group now uses global rather than local to meet requirement for setting ACLs to access shared folders
  • Minor tweaks and bug fixes

 

 

This is what I would call release code as I've now got this up and running in three schools.

 

The things to watch out for however are as follow:

    [*]You need to run the manual script every time you create a new user (possible scheduled task?)

    [*]If you do run as a scheduled task you need to be running as an admin

    [*]The XCACLS.vbs output is annoying with lots of pop up CMD windows but it does avoid the warning boxes re: "not using cscript" that //B mode creates.

    [*]Time wise the manual script requires approximately 1 minute per class of 25 children so if you have a big school it'll take some time.[/list:o]

     

     

    Beyond that functionality hasn't changed a huge amount.. The three script approach seems to work much better but remember you still need scripts to run asynchronously.

    user_folders.zip

  • 1 year later...
Posted

Been doing a LOT of work on this after I discovered a heap of problems with some of my login scripts in one school.

 

It's still very much in development so there's no new code to share until I've finished off the remainder and done a bit more testing but just to share:

 

  1. Found a useful reference for "including" vbs code How to include a file from within a VBScript script
  2. Use the above to break variables out into a config file and make like a LOT easier for multiple site configs
  3. Resolved a problem with waitforfolder() fn... Somehow a variable was being changed by reference in a rather unexpected way... Redefining the variable after any createflds() calls has fixed that
  4. The use of XCACLs.vbs has been tightened up
  5. Added more class OU's to the list and resolved a precedence issue with class 10/11/12/etc... being put into Class 1 *oops*
  6. Class-Foo accounts (ie: for whole class) now default their home directory to the class shared folder
  7. Script waits for the wshNetwork.UserName to be defined before it tries to do anything avoiding a few errors
  8. Fixed an issue that stopped new OU members from being added to the proper security group for the class.
  9. Now possible to specify an individual to add to the system and relevant class security group without running through EVERY user.

 

 

All, in all it's looking a lot neater and a heck of a lot easier to use than before... I need to sort out the staff version and test a few bits with the mapped login but otherwise... Looking good... :)

Posted (edited)

Right... I finally got the code ready for distribution.

 

A couple of additional features are now included:

  • map-drives.setup file included for all drive mapping not already handled by the main script (eg: apps drives, etc..)
  • printer.setup file included. Basically a printer loader and default setup script.. Called right at the end.

 

Before you do anything you will need to setup the school.config with the appropriate variables and then run the "usr_fldr_struc_create_man.vbs" file on the server in order to get it to create the relevant folders and set permissions. Expect it to take quite a while.

 

Once you've run it first time, you will need to run it again for any new accounts you create that require adding to usergroups, and have folders setup, etc... This is made easier in this version thanks to the new "strIndUser" variable at the top of the -man.vbs file. You specify the username you've added and wish to incorporate into the structure and the script will run through and do the work on just that one user, adding them to the relevant class, security group, etc... It doesn't do groups yet but I may add that functionality in the future.

 

 

Past that the rest is login script.

In a nutshell the "usr_fldr_map_login.vbs" script ensures that you get all your scripts to run but in a specific order and only requiring you to setup that single script either in the AD > Profile > Logon Script field or as your login script GPO.

 

In my case it means I no longer have to run scripts asynchronously so that could be disabled in GPO too if you use it in a similar manner.

 

 

Caveat:

One thing I have noticed with this script set is that you have to login once successfully, log off and the log in again, in order to get the drive mappings from the map-drives.setup to work properly. Not sure why yet but that's a known "Feature".

User folders-2009-05-03.zip

Edited by contink
typo
Posted

This looks rather interesting, well done contink

 

I'll have a play with this on tuesday and give you some feedback.

 

James.

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...