2024-08-09 13:56:16 +00:00
|
|
|
using namespace System.Security.AccessControl;
|
|
|
|
using namespace System.Security.Principal;
|
|
|
|
|
2024-08-09 02:29:26 +00:00
|
|
|
$null = New-Module {
|
|
|
|
$uacOption = "EnableLUA";
|
|
|
|
$systemPolicyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
|
|
|
|
|
|
|
|
$uacSetter = {
|
|
|
|
param(
|
|
|
|
[bool] $Value
|
|
|
|
)
|
|
|
|
|
|
|
|
Set-ItemProperty -Path $systemPolicyPath -Name $uacOption -Value ([int]$Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Determines whether UAC is enabled.
|
|
|
|
#>
|
|
|
|
function Get-UACStatus {
|
|
|
|
[bool](Get-ItemProperty -Path $systemPolicyPath -Name $uacOption);
|
|
|
|
}
|
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Enables UAC.
|
|
|
|
#>
|
|
|
|
function Enable-UAC {
|
|
|
|
& $uacSetter $true;
|
|
|
|
}
|
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Disables UAC.
|
|
|
|
#>
|
|
|
|
function Disable-UAC {
|
|
|
|
& $uacSetter $false;
|
|
|
|
}
|
2024-08-09 13:56:16 +00:00
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Sets read/write permissions for users at the specified path.
|
|
|
|
|
|
|
|
.PARAMETER Path
|
|
|
|
The path to allow access to users.
|
|
|
|
#>
|
|
|
|
function Set-UserPermissions {
|
|
|
|
param(
|
|
|
|
[string] $Path
|
|
|
|
)
|
|
|
|
|
|
|
|
$acl = Get-Acl $Path;
|
|
|
|
|
|
|
|
$acl.AddAccessRule(
|
|
|
|
[FileSystemAccessRule]::new(
|
|
|
|
[SecurityIdentifier]::new([WellKnownSidType]::BuiltinUsersSid, $null),
|
|
|
|
[FileSystemRights]::FullControl,
|
2024-08-19 00:24:45 +00:00
|
|
|
(& {
|
|
|
|
if (Test-Path -PathType Container $Path) {
|
|
|
|
[InheritanceFlags]::ObjectInherit -bor [InheritanceFlags]::ContainerInherit
|
|
|
|
} else {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
}),
|
2024-08-09 13:56:16 +00:00
|
|
|
[PropagationFlags]::InheritOnly,
|
|
|
|
[AccessControlType]::Allow));
|
|
|
|
|
|
|
|
Set-Acl $Path $acl;
|
|
|
|
}
|
2024-08-09 02:29:26 +00:00
|
|
|
};
|