Scripting Question

How do i get a file's permission for administrator using Vbscript?

01/20/2015 3097 views
Let's say i have a file in a specific folder. Now how do i get administrator's permission for this file. Thanks in advance.
0 Comments   [ + ] Show comments


Community Chosen Answer


I think you are looking for this script

Option Explicit
On Error Resume Next
Dim objShell,objFSO, ProgramFiles, strFile, strNTGroup

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

ProgramFiles = objShell.ExpandEnvironmentStrings("%ProgramFiles%")

strFile =  ProgramFiles & "\MyApplication\MyFile_1.Ext"
strNTGroup = "Users"

‘Assign User Permissions to File.

If objFSO.FileExists(strFile) Then
 objShell.Run "%COMSPEC% /c cacls """ & strFile & """ /T /E /G " & strNTGroup & ":F", 0, True
End If

Set objFSO = Nothing
Set objShell = Nothing

Answered 01/21/2015 by: jagadeish
Red Belt

All Answers

The script above needs to be run with administrator rights in order to apply the permissions.
I am wondering whether the question is misleading and the O/P is asking how to run the file "as administrator".

Answered 01/21/2015 by: EdT
Red Belt

  • I'm sorry If i mislead something. Let me be transparent. Usually an administrator has following permissions over a file: "Full control","Modify","Read","Write","Read & Execute". But an user may not have all these permission over a file. So i need a script that can tell me what kind of permission an user has and an administrator has for a particular file. Hope things clear up. Thanks in advance. I appreciate your prompt response. - Aniket

Would cacls or icacls not work in this case..

here is a link to vbs listing the acls on file objects, hope it helps


Answered 01/22/2015 by: Badger
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