Disclaimer

Wednesday 14 November 2012

File & registry permissions with subinacl

Sample script that makes use of subinacl to modfiy permissions for files and/or registry, in this case I have done a function for alter file permissions, when I have to do somehthing for the registry I will add a new function or modify this one (you will need to obtain a copy of subinacl.exe from Microsoft which I believe is free):

Sub SetPermissions(strTarget, strUser, strAccess)
  'On Error Resume Next
  Dim wshShell
  Set WshShell = WScript.CreateObject("WScript.Shell")
  wshShell.Run "subinacl.exe /subdirectories=directoriesonly " & """" & strTarget & """" & " /grant=" & """" & strUser & """" & "=" & strAccess, 0, True
  wshShell.Run "subinacl.exe /subdirectories=directoriesonly " & """" & strTarget & "\*.*" & """" & " /grant=" & """" & strUser & """" & "=" & strAccess, 0, True
  wshShell.Run "subinacl.exe /subdirectories=filesonly " & """" & strTarget & "\*.*" & """" & " /grant=" & """" & StrUser & """" & "=" & strAccess, 0, True
End Sub

'Ignore the following lines more as reference to myself for when I get around to doing it for registry keys
  wshShell.Run "subinacl.exe /keyreg " & """" & "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Bloomberg L.P." & """" & " /grant=" & """" & "Authenticated Users" & """" & "=" & "F", 0, True
  wshShell.Run "subinacl.exe /keyreg " & """" & "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Bloomberg L.P." & """" & " /grant=" & """" & "Authenticated Users" & """" & "=" & "F", 0, True

No comments:

Post a Comment