Scripting Question

How to set file permission with VBScript?

01/15/2015 12360 views

Hi Folks,

I am trying to write a VBScript to set Modify permission on a file for Users Group. However, I have not been able to figure out what's going wrong with the Script. Below is the Script I have. Any help will be appreciated. Thanks is advance.

On Error Resume Next

Dim sAllUsersAppData

Set objShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

sAllUsersAppData = objShell.ExpandEnvironmentStrings("%ProgramData%")

strFile = sAllUsersAppData & "\Folder1\Folder2\Folder3\File.ini"
strNTGroup = "Users"
If fso.FileExists(strFile)=true Then
objShell.Run "%COMSPEC% /c cacls " & strFile & " /T /E /G " & strNTGroup & ":C", 0, True
End If

Answer Summary:
0 Comments   [ + ] Show comments


Community Chosen Answer

If objFSO.FileExists(strFile) Then
objShell.Run "%COMSPEC% /c cacls """ & strFile & """ /T /E /G " & strNTGroup & ":C", 0, True
End If
Answered 01/16/2015 by: jagadeish
Red Belt

All Answers


Maybe this will help you :

The CACLS command does not provide a /Y switch to automatically answer 'Y' to the Y/N prompt. However, you can pipe the 'Y' character into the CACLS command using ECHO, use the following syntax:
ECHO Y| CACLS filename /g username:permission

It seems "cacls.exe"  is not recommand for windows 7 . You should be try with "setacl.exe" or "xcals.vbs".

Answered 01/16/2015 by: egiberne
Second Degree Brown Belt

Did you have look in making a powershell script?
This stuff is build in, not great, but to improve that there is a Powershell NTFS module.
Perhaps more powerful then VBscript.
Just google and there are a lot examples.
Answered 01/16/2015 by: dedenker
3rd Degree Black Belt

  • Hi,
    I actually wanted to have PowerShell to get this, however, i am fairly new for PowerShell Script.

    Any link would be great!
    • https://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85
      Is one I talked about.
      Then one of the example's you can use.
      And about Powershell, is it nothing special if you have some scripting experience.
      And lots of info pages if you start from zero.
      Take a look here: http://ss64.com/ps/
Firstly, please use the 'Code' style when posting code.

Secondly, there is a nice VBS class file authored internally within Microsoft which you'll find useful if you want to stick with VBS. It will obviously give you a lot more control over error-trapping and error reporting which is way too convoluted to do with command-line tools like CACLS, SetACL etc.
Answered 01/16/2015 by: VBScab
Red Belt

If objFSO.FileExists(strFile) Then
objShell.Run "%COMSPEC% /c cacls """ & strFile & """ /T /E /G " & strNTGroup & ":C", 0, True
End If
Answered 01/16/2015 by: jagadeish
Red Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


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