/build/static/layout/Breadcrumb_cap_w.png

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

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

Answers (3)

Posted by: jagadeish 9 years ago
Red Belt
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

Posted by: EdT 9 years ago
Red Belt
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".


Comments:
  • 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 - Aniket214 9 years ago
Posted by: Badger 9 years ago
Red Belt
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

 
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