/build/static/layout/Breadcrumb_cap_w.png

How to set file permission with VBScript?

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





0 Comments   [ + ] Show comments

Answers (5)

Answer Summary:
Posted by: jagadeish 9 years ago
Red Belt
1
If objFSO.FileExists(strFile) Then
objShell.Run "%COMSPEC% /c cacls """ & strFile & """ /T /E /G " & strNTGroup & ":C", 0, True
End If
Posted by: egiberne 9 years ago
Second Degree Brown Belt
0
Hello,

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".

Regards
Posted by: dedenker 9 years ago
3rd Degree Black Belt
0
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.

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

    Any link would be great! - shrestha.rajiv.k 9 years ago
    • 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/ - dedenker 9 years ago
Posted by: anonymous_9363 9 years ago
Red Belt
0
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.

Comments:
Posted by: jagadeish 9 years ago
Red Belt
0
If objFSO.FileExists(strFile) Then
objShell.Run "%COMSPEC% /c cacls """ & strFile & """ /T /E /G " & strNTGroup & ":C", 0, True
End If

Comments:

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:

Share

 
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