How do i get a file's permission for administrator using Vbscript?
Answers (3)
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
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
Would cacls or icacls not work in this case..
here is a link to vbs listing the acls on file objects, hope it helps