+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, batch or VBS to copy a folder to certain home drives only in Coding and Web Development; I've been asked about copying a folder full of stuff in certain student areas for our functional ICT exam. The ...
  1. #1
    Oops_my_bad's Avatar
    Join Date
    Jan 2007
    Man chest hair
    Thank Post
    Thanked 53 Times in 50 Posts
    Rep Power

    batch or VBS to copy a folder to certain home drives only

    I've been asked about copying a folder full of stuff in certain student areas for our functional ICT exam. The problem is I don't want it going in everyones - just a small selection. I'm guessing I need some sort of "for" loop which only operates on given student areas -but not sure how to go about this Be grateful if anyone can help!?

  2. #2

    Join Date
    Jul 2007
    Rural heck
    Thank Post
    Thanked 433 Times in 352 Posts
    Rep Power
    The easiest way to do this would probably to put the particular users in a different OU (it could even a child OU) and then add an extra GPO that runs the script.

    Is this something you want to run once or everytime they log on. If it's something you only need to do once another quick and dirty method is to use the CONCATENATE function in Excel to build a batch script that'll do what you need.
    Last edited by K.C.Leblanc; 5th May 2009 at 01:33 PM.

  3. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Thank Post
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    you could do something similiar to using a boolean inside of a for loop as per here

    Delete Local Profiles (VBScript)

    Const LocalDocumentsFolder = "C:\Documents and Settings\"
    set objFSO = createobject("Scripting.FileSystemObject")
    set objFolder = objFSO.GetFolder(localdocumentsfolder)
    on error resume next
    for each fldr in objFolder.SubFolders
    	if not isexception(fldr.name) then
    		objFSO.DeleteFolder fldr.path, True
    	end if
    Function isException(byval foldername)
    	select case foldername
    		case "All Users"
    			isException = True
    		case "Default User"
    			isException = True
    		case "LocalService"
    			isException = True
    		case "NetworkService"
    			isException = True
    		case "Administrator"
    			isException = True
    		case Else
    			isException = False
    	End Select
    End Function
    You would need to alter the function a bit so that it got the usernames instead of folder names and if the isException is = to true then it wont delete it and if it is = false then it will delete it.

    However in your case you would alter the code above to copy instead of delete.
    Last edited by mac_shinobi; 5th May 2009 at 01:55 PM.

  4. #4

    Join Date
    Aug 2005
    Thank Post
    Thanked 529 Times in 452 Posts
    Blog Entries
    Rep Power
    Easier to put users in security groups than OUs - you can only be in 1 OU but multiple groups.

    Code below looks for users in group called "ma users" and copies the file listed at the start (c:\temp\special.doc) into their homedir. Not sure if that's the sort of thing you're trying to do.

    sGroup="ma users"
    set ofso=createobject("scripting.filesystemobject")
    Set oRootDSE=GetObject("LDAP://RootDSE")
    Set oConn = CreateObject("ADODB.Connection")
    oConn.Provider = "ADsDSOObject"
    Set oCommand = CreateObject("ADODB.Command")
    oCommand.ActiveConnection = oConn
    oCommand.properties("Page Size")=100
    oCommand.CommandText = "<LDAP://" & sRoot & ">;(sAMAccountName=" & sGroup & ");sAMAccountName,distinguishedname;subTree"
    on error resume next
    Set oRS = oCommand.Execute
    if not ors.eof then
      wscript.echo ors("distinguishedname")
      set oGroup=getobject("LDAP://" & ors("distinguishedname"))
      for each oMember in ogroup.members
        set oUser=getobject("LDAP://" & oMember.distinguishedname)
        ofso.copyfile sFile, sHomeDir, true
    end if

+ Post New Thread

Similar Threads

  1. Batch file to copy user profile
    By googlemad in forum Windows
    Replies: 2
    Last Post: 16th October 2010, 12:08 AM
  2. Batch copy files and folders up one level
    By PrimaryTech in forum Windows
    Replies: 0
    Last Post: 13th March 2009, 10:28 AM
  3. vbscript to copy a folder & delete a folder
    By MicrodigitUK in forum Scripts
    Replies: 2
    Last Post: 29th January 2009, 01:43 PM
  4. VBS Script to copy a folder
    By FN-GM in forum Scripts
    Replies: 2
    Last Post: 23rd February 2008, 02:08 PM
  5. Replies: 2
    Last Post: 1st October 2005, 03:55 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts