O Controle de Conta de Usuário (UAC) é um recurso de segurança vital nos sistemas operacionais Windows. Ele atua como um guardião, impedindo alterações não autorizadas em seu computador. O UAC funciona definindo diferentes níveis de permissões de usuário, variando de sempre notificar sobre alterações a nunca notificar. Ao compreender esses níveis e como eles afetam as permissões de usuário, os profissionais de TI podem proteger melhor seus sistemas.
Histórico
Introduzido com o Windows Vista, o UAC tem sido uma pedra angular da segurança do Windows. Quando se tenta fazer determinadas alterações, o UAC solicita aos usuários permissão ou uma senha de administrador antes de permitir que a tarefa prossiga. Esse script, adaptado ao Windows 7 e ao Windows Server 2012 em diante, oferece uma maneira de configurar programaticamente essas definições de UAC.
O roteiro
#Requires -Version 2.0
<#
.SYNOPSIS
Configures UAC.
.DESCRIPTION
Configures UAC to defaults if no parameters are specified.
.EXAMPLE
No parameters needed.
Sets all UAC settings to Microsoft's defaults.
.EXAMPLE
-ConsentPromptBehaviorAdmin 5
Sets ConsentPromptBehaviorAdmin to 5
.EXAMPLE
PS C:> Set-Uac.ps1
Sets all UAC settings to MS defaults.
.OUTPUTS
None
.NOTES
Minimum OS Architecture Supported: Windows 7, Windows Server 2012
This script will show before and after UAC settings.
Release Notes:
Initial Release
By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider.
Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
.COMPONENT
LocalUserAccountManagement
#>
[CmdletBinding()]
param (
[Parameter()][ValidateRange(0, 5)][int]$ConsentPromptBehaviorAdmin = 5,
[Parameter()][ValidateRange(0, 3)][int]$ConsentPromptBehaviorUser = 3,
[Parameter()][ValidateRange(0, 1)][int]$EnableInstallerDetection = 1,
[Parameter()][ValidateRange(0, 1)][int]$EnableLUA = 1,
[Parameter()][ValidateRange(0, 1)][int]$EnableVirtualization = 1,
[Parameter()][ValidateRange(0, 1)][int]$PromptOnSecureDesktop = 1,
[Parameter()][ValidateRange(0, 1)][int]$ValidateAdminCodeSignatures = 0,
[Parameter()][ValidateRange(0, 1)][int]$FilterAdministratorToken = 0
)
begin {
function Test-IsElevated {
$id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$p = New-Object System.Security.Principal.WindowsPrincipal($id)
if ($p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator))
{ Write-Output $true }
else
{ Write-Output $false }
}
function Set-ItemProp {
param (
$Path,
$Name,
$Value,
[ValidateSet("DWord", "QWord", "String", "ExpandedString", "Binary", "MultiString", "Unknown")]
$PropertyType = "DWord"
)
if ((Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue)) {
Set-ItemProperty -Path $Path -Name $Name -Value $Value -Force -Confirm:$false | Out-Null
}
else {
New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $PropertyType -Force -Confirm:$false | Out-Null
}
}
}
process {
if (-not (Test-IsElevated)) {
Write-Error -Message "Access Denied. Please run with Administrator privileges."
exit 1
}
$path = "HKLM:SOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem"
$filter = "ConsentPromptBehaviorAdmin|ConsentPromptBehaviorUser|EnableInstallerDetection|EnableLUA|EnableVirtualization|PromptOnSecureDesktop|ValidateAdminCodeSignatures|FilterAdministratorToken"
Write-Host "Before:"
(Get-ItemProperty $path).psobject.properties | Where-Object { $_.name -match $filter } | Select-Object name, value
try {
$filter -split '|' | ForEach-Object {
Set-ItemProp -Path $Path -Name $_ -Value (Get-Variable -Name $_).Value
}
}
catch {
Write-Error $_
exit 1
}
Write-Host "After:"
(Get-ItemProperty $path).psobject.properties | Where-Object { $_.name -match $filter } | Select-Object name, value
}
end {}
Acesse mais de 300 scripts no NinjaOne Dojo
Casos de uso em potencial
Considere um cenário em que uma empresa esteja implantando um novo software que exija configurações específicas do UAC para otimizar o desempenho e a segurança. Em vez de configurar manualmente cada computador, a equipe de TI pode usar esse script para garantir que cada máquina seja configurada corretamente. Além disso, para empresas que precisam aderir a normas de segurança rígidas, esse script pode ajudar a garantir a conformidade padronizando as configurações do UAC em todos os setores.
Implicações de segurança
As configurações do UAC desempenham um papel fundamental na segurança do sistema. Configurações incorretas podem, inadvertidamente, dar luz verde para que o malware seja instalado ou executado sem a permissão do usuário. Ao automatizar o processo de configuração, esse script reduz as chances de erro humano, mas ressalta a importância de compreender as implicações de cada configuração.
Recomendações
- Sempre faça backup do registro antes de fazer alterações para se proteger contra possíveis problemas.
- Teste o script em um único computador ou em um ambiente controlado antes de implementá-lo em toda a rede.
- Mantenha-se atualizado sobre as práticas recomendadas de configurações do UAC para garantir a segurança ideal.
Considerações finais
No cenário em constante evolução da segurança de TI, ferramentas como esse script de configuração do UAC são inestimáveis. Ao compreender e aproveitar essas ferramentas, os profissionais de TI podem garantir um ambiente mais seguro e eficiente para seus usuários.