Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Check for elevated privileges
- if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
- Write-Error "This script must be run as an Administrator. Please run it again with elevated privileges."
- exit
- }
- param(
- [Parameter(Mandatory=$true)]
- [ValidateSet("Enable","Disable")]
- [string]$Action
- )
- function Backup-Registry {
- $backupFile = "HKLM_SOFTWARE_Policies_Microsoft_Windows_DeviceInstall_Settings.reg"
- reg export "HKLM\SOFTWARE\Policies\Microsoft\Windows\DeviceInstall\Settings" $backupFile
- Write-Host "Registry backup created: $backupFile"
- }
- function Set-DeviceInstallPolicy {
- param([string]$Action)
- Backup-Registry
- $path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DeviceInstall\Settings"
- $disableSystemUpdateAccessValue = if ($Action -eq "Disable") { 1 } else { 0 }
- $disableDeviceMetadataRetrievalValue = if ($Action -eq "Disable") { 1 } else { 0 }
- New-ItemProperty -Path $path -Name "DisableSystemUpdateAccess" -Value $disableSystemUpdateAccessValue -PropertyType DWord -Force | Out-Null
- New-ItemProperty -Path $path -Name "DisableDeviceMetadataRetrieval" -Value $disableDeviceMetadataRetrievalValue -PropertyType DWord -Force | Out-Null
- if ($Action -eq "Disable") {
- Write-Host "Automatic downloading of manufacturer apps and custom icons is now disabled."
- } else {
- Write-Host "Automatic downloading of manufacturer apps and custom icons is now enabled."
- }
- }
- # Execute the function with the provided action
- Set-DeviceInstallPolicy -Action $Action
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement