Sample scripts for setting access rights on file- and registry objects.
Setting file system rights
This script can be used to set file system rights and log the process in the Scense Executive Log.
This script uses the ‘SubInACL’ resource kit tool.
The group specified at the TaskSet level will be granted rights for the specified file(s) and/or folder(s).
'<ScenseScriptHeader>
' <ScriptParameters>
' <Parameter Name="Type" ScriptVariableName="vType">
' <GUI Control="DropDownList" Tooltip="Select the type of object to set access rights to (folder or file)">
' <ListElements>
' <Element Name="File" />
' <Element Name="Folder" />
' </ListElements>
' </GUI>
' </Parameter>
' <Parameter Name="Target Path" ScriptVariableName="vTargetPath">
' <GUI Control="TextBox" />
' </Parameter>
' <Parameter Name="Access Rights" ScriptVariableName="vAccessRights">
' <GUI Control="DropdownList">
' <ListElements>
' <Element Name="Full Control" Value="F" />
' <Element Name="Change" Value="C" />
' <Element Name="Read" Value="R" />
' <Element Name="Change Permissions" Value="P" />
' <Element Name="Take Ownership" Value="O" />
' <Element Name="Execute" Value="X" />
' <Element Name="Read Execute" Value="E" />
' <Element Name="Write" Value="W" />
' <Element Name="Delete" Value="D" />
' </ListElements>
' </GUI>
' </Parameter>
' <Parameter Name="Process sub folders" ScriptVariableName="vSubFolders">
' <GUI Control="CheckBox" ValueType="Boolean" />
' </Parameter>
' </ScriptParameters>
'</ScenseScriptHeader>
'<ParameterCodeBlock>
vType = "Folder"
vTargetPath = "C:\Folder1\Folder2"
vSubFolders = False
vAccessRights = "F"
'</ParameterCodeBlock>
'===============================================================================
' Purpose: Set security for Filesystem from taskset
'===============================================================================
'Global variables
Dim wshshell
Dim Groepsnaam
Dim DomeinNaam
Dim ToolingDirectory
Dim LogFileName
Dim InstallLocation
Dim SystemDrive
Dim SystemRoot
Dim InstallType
Dim CmdLine
Sub Scense_Main()
GroepsNaam = ReplaceVariables("%TasksetReferenceName%")
DomeinNaam = ReplaceVariables("%UserDomain%")
ToolingDirectory = ReplaceVariables("%ToolingDirectory%")
InstallLocation = ReplaceVariables("%InstallLocation%")
InstallType = ReplaceVariables("%InstallType%")
SystemDrive = ReplaceVariables("%SystemDrive%")
SystemRoot = ReplaceVariables("%SystemRoot%")
'Specify LogfileName
LogFileName = ReplaceVariables("%Temp%") & "\Subinacl.log"
Set WshShell = CreateObject("WScript.Shell")
'-------------------------------------------------------------------------------
'Use the variables from the header
vTargetPath = ReplaceVariables(vTargetPath)
If vType = "File" Then
SingleFile vTargetPath, vAccessRights
Else
SingleFolder vTargetPath, vAccessRights
If vSubFolders Then
SubFolderFiles vTargetPath, vAccessRights
End If
End If
'-------------------------------------------------------------------------------
Set wshshell=Nothing
End Sub
Sub SingleFile(File, Permission)
'Set permissions
CmdLine = "\subinacl.exe /errorlog=""" & LogFileName & """ /File """ & _
File & """ /grant=""" & DomeinNaam & "\" & GroepsNaam & """=" & Permission
WriteScenseLog CmdLine
Call WshShell.Run(ToolingDirectory & CmdLine, 0, True)
'Save the logging
WriteFileToScenseLog
End Sub
Sub SingleFolder(Folder, Permission)
'Set permissions
CmdLine = "\subinacl.exe /errorlog=""" & LogFileName & _
""" /Subdirectories """ & Folder & """ /grant=""" & _
DomeinNaam & "\" & GroepsNaam & """=" & Permission
WriteScenseLog CmdLine
Call WshShell.Run(ToolingDirectory & CmdLine, 0, True)
'Save the logging
WriteFileToScenseLog
End Sub
Sub SubFolderFiles(Folder, Permission)
'Set permissions
CmdLine = "\subinacl.exe /errorlog=""" & LogFileName & _
""" /Subdirectories """ & Folder & "\*.*"" /grant=""" & _
DomeinNaam & "\" & GroepsNaam & """=" & Permission
WriteScenseLog CmdLine
Call WshShell.Run(ToolingDirectory & CmdLine, 0, True)
'Save the logging
WriteFileToScenseLog
End Sub
Sub WriteFileToScenseLog
Dim fso, ts, s
Set fso = CreateObject("Scripting.FileSystemObject")
' Read the contents of the file.
Set ts = fso.OpenTextFile(LogFileName, 1, False, -1)
Do While Not ts.AtEndOfstream
s = ts.ReadLine
If Len(Trim(s)) > 0 Then
WriteScenseLog s
End If
Loop
ts.Close
Set ts = Nothing
'Delete the logfile
Set f = fso.GetFile(LogFileName)
f.Delete
Set f = Nothing
Set fso = Nothing
End Sub
Set registry rights
This script can be used to set registry rights and log the process in the Scense Executive Log.
This script uses the ‘SubInACL’ resource kit tool.
The group specified at the TaskSet level will be granted rights to the specified key(s)
'<ScenseScriptHeader>
' <ScriptParameters>
' <Parameter Name="Target Path" ScriptVariableName="vTargetPath">
' <GUI Control="TextBox" />
' </Parameter>
' <Parameter Name="Access Rights" ScriptVariableName="vAccessRights">
' <GUI Control="DropdownList">
' <ListElements>
' <Element Name="Full Control" Value="F" />
' <Element Name="Change" Value="C" />
' <Element Name="Read" Value="R" />
' <Element Name="Change Permissions" Value="P" />
' <Element Name="Take Ownership" Value="O" />
' <Element Name="Execute" Value="X" />
' <Element Name="Read Execute" Value="E" />
' <Element Name="Write" Value="W" />
' <Element Name="Delete" Value="D" />
' </ListElements>
' </GUI>
' </Parameter>
' <Parameter Name="Process sub keys" ScriptVariableName="vSubKeys">
' <GUI Control="CheckBox" ValueType="Boolean" />
' </Parameter>
' </ScriptParameters>
'</ScenseScriptHeader>
'<ParameterCodeBlock>
vTargetPath = "HKEY_CURRENT_USER\SOFTWARE\Scense"
vSubKeys = False
vAccessRights = "F"
'</ParameterCodeBlock>
'===============================================================================
' Purpose: Set security for registry from taskset
'===============================================================================
'Global variables
Dim wshshell
Dim Groepsnaam
Dim DomeinNaam
Dim ToolingDirectory
Dim LogFileName
Dim CmdLine
Sub Scense_Main()
GroepsNaam = ReplaceVariables("%TasksetReferenceName%")
DomeinNaam = ReplaceVariables("%UserDomain%")
ToolingDirectory = ReplaceVariables("%ToolingDirectory%")
'Specify LogfileName
LogFileName = ReplaceVariables("%Temp%") & "\Subinacl.log"
Set WshShell = CreateObject("WScript.Shell")
'-------------------------------------------------------------------------------
If vSubKeys Then
SubKeyReg vTargetPath, vAccessRights
Else
SingleReg vTargetPath, vAccessRights
End If
'-------------------------------------------------------------------------------
'===============================================================================
'The following PACEs are valid For registry key And registry subkey objects
' F = Full Control
' R = Read
' A = Read Control
' Q = Query Value
' S = Set Value
' C = Create SubKey
' E = Enumerate Subkeys
' Y = NotifY
' L = Create Link
' D = Delete
' W = Write DAC
' O = Write Owner
'===============================================================================
Set wshshell=Nothing
End Sub
Sub SingleReg(Key,Permission)
'Set permissions
CmdLine = "\subinacl.exe /errorlog=""" & LogFileName & """ /KeyReg """ & _
Key & """ /grant=""" & DomeinNaam & "\" & GroepsNaam & _
"""=" & Permission
WriteScenseLog CmdLine
Call WshShell.Run(ToolingDirectory & CmdLine, 0, True)
'Save the logging
WriteFileToScenseLog
End Sub
Sub SubKeyReg(Key,Permission)
'Set permissions
CmdLine = "\subinacl.exe /errorlog=""" & LogFileName & """ /SubKeyReg """ & _
Key & """ /grant=""" & DomeinNaam & "\" & GroepsNaam & _
"""=" & Permission
WriteScenseLog CmdLine
Return = WshShell.Run(ToolingDirectory & CmdLine, 0, True)
'Save the logging
WriteFileToScenseLog
End Sub
Sub WriteFileToScenseLog
Dim fso, ts, s
Set fso = CreateObject("Scripting.FileSystemObject")
' Read the contents of the file.
Set ts = fso.OpenTextFile(LogFileName, 1, False, -1)
Do While Not ts.AtEndOfstream
s = ts.ReadLine
If Len(Trim(s)) > 0 Then
WriteScenseLog s
End If
Loop
ts.Close
Set ts = Nothing
'Delete the logfile
Set f = fso.GetFile(LogFileName)
f.Delete
Set f = Nothing
Set fso = Nothing
End Sub