Created
October 8, 2014 14:20
-
-
Save grenade/c3b591983f1e90d50ea3 to your computer and use it in GitHub Desktop.
Allow log4net to create eventlog appenders under the user account specified by $username
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string] $username = "$env:USERDOMAIN\$env:USERNAME" | |
) | |
function GrantAccess ($principle, $log, $access) { | |
$path = ('HKLM:\SYSTEM\CurrentControlSet\services\eventlog\{0}' -f $log) | |
if (Test-Path $path) { | |
Write-Host ('Granting {0} on {1} to {2}' -f $access, $path, $principle) -ForegroundColor Yellow | |
Get-Acl $path | Format-List | |
$acl = Get-Acl $path | |
$rule = New-Object System.Security.AccessControl.RegistryAccessRule($principle, @($access), 'Allow') | |
$acl.AddAccessRule($rule) | |
Set-Acl $path $acl | |
Write-Host ('Granted {0} on {1} to {2}' -f $access, $path, $principle) -ForegroundColor DarkGreen | |
Get-Acl $path | Format-List | |
} else { | |
Write-Error "Cannot acesss $path" | |
} | |
} | |
GrantAccess $username 'Application' 'ReadKey, WriteKey' | |
GrantAccess $username 'Security' 'ReadKey' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment