mcpp661
asked on
Need assistance in setting NTFS folder permissions with VBScript
I have the code below which I found on this and other Web sites and customized it to my needs. It creates a folder on a file server and shares it. However, the last thing I need to do is to add a specific user to the NTFS permissions and assign modify permissions. I want it to retain inherited permissions, but just want to add a user to the ACL and give him/her modify permissions. What is the best way to go about this? Thank you.
Option Explicit
'On Error Resume Next
Dim objFSO, objExcel, objSpread
Dim objNewShare, objWMIService, objUser
Dim strParentFolder, strSheet, strSam, intRow, strFirst, strLast
Dim strShareName, errReturn, strPathName, strComputer, strSharePath
Const FS = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
strSheet = "c:\UsersWithHomeFolders.xls"
strComputer = "server"
strParentFolder = "\\" & strComputer & "\e$\Files\Users\"
' Check to see if spreadsheet exits
If objFSO.FileExists(strSheet) = False Then
MsgBox("The file " & strSheet & " does not exist. Please create the file and run the script again.")
WScript.Quit
End If
' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 3 'Row 1 often contains headings
' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
' Trim function eliminates blank spaces
Do Until objExcel.Cells(intRow,1).Value = ""
strSam = Trim(objExcel.Cells(intRow, 1).Value)
strLast = Trim(objExcel.Cells(intRow, 3).Value)
strFirst = Trim(objExcel.Cells(intRow, 4).Value)
strPathName = strParentFolder & strLast & ", " & strFirst
strShareName = strSam & "$"
strSharePath = "e:\Files\Users\" & strLast & ", " & strFirst
If objFSO.FolderExists(strPathName) = False Then
objFSO.CreateFolder strPathName
'this code creates the share
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")
errReturn = objNewShare.Create(strSharePath, strShareName, FS)
End If
intRow = intRow + 1
Loop
objExcel.Quit
Set objFSO = Nothing
Set objExcel = Nothing
Set objSpread = Nothing
Set objWMIService = Nothing
Set objNewShare = Nothing
WScript.Quit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is CACLS something that's included with Windows or is it an executable that needs downloaded?
No its included in the windows.
ASKER
Well, in the script file do I have to include the path to CACLS? If so, do you know what the path is off the top of your head? Also, the folder permissions I want to set are on a file server but I'm going to run this script from my local workstation, does that mean the objshell.run line will have to be modified to reflect that?
The file is located in c:\windows\syatem32 so you don't need to specify the path.You need to modify the objshell.run ans speciify the UNC path of your file server.
http://www.computerperformance.co.uk/vbscript/vbscript_cacls.htm