$targetUrls = @(
"https://www.google.com",
"http://192.168.1.50",
"https://10.0.0.1",
"https://*.example.com",
"http://intranet-server"
)
$zoneId = 2
$basePathDomains = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains"
$basePathRanges = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges"
Write-Host "Starting process..." -ForegroundColor Cyan
foreach ($url in $targetUrls) {
try {
if ($url -match "^(https?)://(.+)") {
$scheme = $Matches[1]
$hostPart = $Matches[2]
$isIpAddress = $hostPart -match "^\d{1,3}(\.\d{1,3}){3}$"
if ($isIpAddress) {
$safeIpName = "IP_" + $hostPart.Replace(".", "_")
$regKeyPath = Join-Path -Path $basePathRanges -ChildPath $safeIpName
if (!(Test-Path $regKeyPath)) {
New-Item -Path $regKeyPath -Force | Out-Null
}
New-ItemProperty -Path $regKeyPath -Name ":Range" -Value $hostPart -PropertyType String -Force | Out-Null
New-ItemProperty -Path $regKeyPath -Name $scheme -Value $zoneId -PropertyType DWORD -Force | Out-Null
Write-Host "[Added IP] $url" -ForegroundColor Yellow
}
else {
$regKeyPath = Join-Path -Path $basePathDomains -ChildPath $hostPart
if (!(Test-Path $regKeyPath)) {
New-Item -Path $regKeyPath -Force | Out-Null
}
New-ItemProperty -Path $regKeyPath -Name $scheme -Value $zoneId -PropertyType DWORD -Force | Out-Null
Write-Host "[Added Domain] $url" -ForegroundColor Green
}
}
else {
Write-Warning "Invalid Format (must include http/https): $url"
}
}
catch {
Write-Error "Error ($url): $($_.Exception.Message)"
}
}
Write-Host "-----------------------------------------------------------"
Write-Host "Process completed. Please restart your browser to apply settings." -ForegroundColor Cyan