Changes to registry load/unload
This commit is contained in:
10
setupReg.ps1
10
setupReg.ps1
@@ -9,7 +9,11 @@ function UserReg {
|
|||||||
if ($null -ne $UserProfile) {
|
if ($null -ne $UserProfile) {
|
||||||
$UserSID = $UserProfile.SID
|
$UserSID = $UserProfile.SID
|
||||||
if( -not (Test-Path -Path "Registry::HKEY_USERS\$UserSID" -PathType Container) ) {
|
if( -not (Test-Path -Path "Registry::HKEY_USERS\$UserSID" -PathType Container) ) {
|
||||||
REG LOAD HKEY_USERS\$UserSID "C:\Users\$Username\NTUSER.DAT"
|
$res = REG LOAD HKEY_USERS\$UserSID "C:\Users\$Username\NTUSER.DAT"
|
||||||
|
if ($res -ne 0) {
|
||||||
|
Write-Host "Failed to load $Username's HKU registry hive."
|
||||||
|
return $null, $null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Write-Host "Loaded $Username's HKU registry hive."
|
Write-Host "Loaded $Username's HKU registry hive."
|
||||||
return $UserSID, "Registry::HKEY_USERS\$UserSID"
|
return $UserSID, "Registry::HKEY_USERS\$UserSID"
|
||||||
@@ -80,9 +84,9 @@ function SetupEleveReg {
|
|||||||
foreach ($valueName in $applications) {
|
foreach ($valueName in $applications) {
|
||||||
New-ItemProperty -Path $DisallowRunPath -Name $valueName -Value $valueName -PropertyType String
|
New-ItemProperty -Path $DisallowRunPath -Name $valueName -Value $valueName -PropertyType String
|
||||||
}
|
}
|
||||||
Write-Host "Added entries to DisallowRun for cmd.exe and powershell.exe."
|
Write-Host "Added registry entries"
|
||||||
Write-Host "Unloading registry HIVE"
|
Write-Host "Unloading registry HIVE"
|
||||||
REG UNLOAD HKEY_USERS\$UserSID
|
Start-Process -FilePath "cmd.exe" -Verb RunAs -ArgumentList "REG UNLOAD HKEY_USERS\$UserSID"
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Unable to get the user's HKU registry."
|
Write-Host "Unable to get the user's HKU registry."
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user