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
Answers (5)
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
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
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:
-
Thanks for info. Appreciate it! - shrestha.rajiv.k 9 years ago
Comments:
-
Thanks Jagadeish. - shrestha.rajiv.k 9 years ago