MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.
Option Explicit Dim strHomeFolder, strHome, strUser Dim objFSO, objShell, intRunError Dim oFSO, sFile, oFile, sText ' Note you will have to amend the following variables strHome = "D:\Users\" Set objFSO = CreateObject("Scripting.FileSystemObject") Set oFSO = CreateObject("Scripting.FileSystemObject") sFile = "D:\Users\users.txt" ' Create a shell for cmd and CACLS Set objShell = CreateObject("Wscript.Shell") ' Here is the loop that cycles through the cells If oFSO.FileExists(sFile) Then Set oFile = oFSO.OpenTextFile(sFile, 1) Do While Not oFile.AtEndOfStream sText = oFile.ReadLine If Trim(sText) <> "" Then strUser = sText call HomeDir ' I decided to use a subroutine End If Loop oFile.Close Else WScript.Echo "The file was not there." End If Sub HomeDir() strHomeFolder = strHome & strUser If strHomeFolder <> "" Then If Not objFSO.FolderExists(strHomeFolder) Then On Error Resume Next objFSO.CreateFolder strHomeFolder If Err.Number <> 0 Then On Error GoTo 0 Wscript.Echo "Cannot create: " & strHomeFolder End If On Error GoTo 0 End If If objFSO.FolderExists(strHomeFolder) Then ' Assign user permission to home folder. intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls "_ & strHomeFolder & " /E /c /g " & strUser & ":C" , 2, True) If intRunError <> 0 Then Wscript.Echo "Error assigning permissions for user " _ & strUser & " to home folder " & strHomeFolder End If End If End If End Sub WScript.Quit
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.