/build/static/layout/Breadcrumb_cap_w.png

VBscript to apply permissions to a folder using CACLS

hi all,

Here is the vbscript to apply permissions to a folder uing cacls,since, setACL has a complex syntax, i thought to use cacls.exe present in system to apply permisions to a folder just replace the folder where u wish to apply permissions 

hope u find it helpful

Option Explicit
Dim strHomeFolder, strHome, strUser,WshShell,SysRoot
Dim intRunError, objShell, objFSO

Set WshShell = CreateObject("Wscript.Shell")
SysRoot = WshShell.ExpandEnvironmentStrings("%SystemDrive%")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strHomeFolder = SysRoot & "\Personal"
msgbox strHomeFolder
If objFSO.FolderExists(strHomeFolder) Then
msgbox"start"
' Assign user permission to home folder.
intRunError = WshShell.Run("%COMSPEC% /c Echo Y| cacls " _
& strHomeFolder & " /e /c /g Users:F ", 2, True)
msgbox intRunError
   If intRunError <> 0 Then
   Wscript.Echo "Error assigning permissions for user " _
   & strUser & " to home folder " & strHomeFolder
   End If
End If

WScript.Quit


Comments

  • One small suggestion here.. Do not give Full Control permission to any folder for the Users group when you implement this script in msi.. Instead you can give only Read/Write permission to the users.. - jagadeish 11 years ago
    • Hello,
      Yes I understand what you are saying....but i had to give permissions to a folder of mine, which happened to be in rootdrive(C:\), and the application shortcut worked only after giving full permissions to that folder. Anyways, since this script can be modified as per the user requirement, i just wrote it. Another purpose behind writing this script was removing the dependency on secacl exe to give permissions to folder, since, its syntax is a bit complicated. - talonsprem87 11 years ago
  • Have you tried with Modify and Write Permission for your application.. - jagadeish 11 years ago
    • Yes, i did try the modify permissions too.....but later on , i had a word with the vendor on that front and later it was confirmed that the application would work after giving full permissions to the installdir - talonsprem87 11 years ago
  • In Windows 7, if I put the Personal folder inside the Program Files path (ie. C:\Program Files\Personal) it does not work for me. Anyone know why? - dmack 11 years ago
  • thinking it's either the space in the path or UAC permissions in windows 7. Any help is appreciated. - dmack 11 years ago
This post is locked
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ