Add a function for allowing user access

This commit is contained in:
Manuel Thalmann 2024-08-09 15:56:16 +02:00
parent 92e4889417
commit 505ee2ad34
2 changed files with 30 additions and 11 deletions

View file

@ -1,3 +1,6 @@
using namespace System.Security.AccessControl;
using namespace System.Security.Principal;
$null = New-Module { $null = New-Module {
$uacOption = "EnableLUA"; $uacOption = "EnableLUA";
$systemPolicyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; $systemPolicyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
@ -33,4 +36,29 @@ $null = New-Module {
function Disable-UAC { function Disable-UAC {
& $uacSetter $false; & $uacSetter $false;
} }
<#
.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,
[InheritanceFlags]::ObjectInherit -bor [InheritanceFlags]::ContainerInherit,
[PropagationFlags]::InheritOnly,
[AccessControlType]::Allow));
Set-Acl $Path $acl;
}
}; };

View file

@ -6,6 +6,7 @@ param(
[hashtable] $Arguments [hashtable] $Arguments
) )
. "$PSScriptRoot/../../Scripts/Security.ps1";
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; . "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
. "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1"; . "$PSScriptRoot/../../../Common/Types/InstallerAction.ps1";
@ -19,18 +20,8 @@ Start-SoftwareInstaller @PSBoundParameters `
git clone "https://github.com/jasongin/nvs.git" $env:NVS_HOME; git clone "https://github.com/jasongin/nvs.git" $env:NVS_HOME;
& "$env:NVS_HOME\nvs.cmd" install; & "$env:NVS_HOME\nvs.cmd" install;
$acl = Get-Acl $env:NVS_HOME;
$acl.AddAccessRule(
[FileSystemAccessRule]::new(
[SecurityIdentifier]::new([WellKnownSidType]::BuiltinUsersSid, $null),
[FileSystemRights]::FullControl,
[InheritanceFlags]::ObjectInherit -bor [InheritanceFlags]::ContainerInherit,
[PropagationFlags]::InheritOnly,
[AccessControlType]::Allow));
Set-Acl $env:NVS_HOME $acl;
refreshenv; refreshenv;
Set-UserPermissions $env:NVS_HOME;
& $Installer -Action ([InstallerAction]::Configure); & $Installer -Action ([InstallerAction]::Configure);
} ` } `
-Configurator { -Configurator {