/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


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

01/20/2015 2900 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

Comments



Community Chosen Answer

2

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

0
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
0

Would cacls or icacls not work in this case..

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

VBScript-Recursive-ACL-List

Answered 01/22/2015 by: Badger
Red Belt

 
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