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   [ - ] Hide Comments


Please log in to comment

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

Please log in to comment
Answer this question or Comment on this question for clarity


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
Please log in to comment

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

Please log in to comment