This repository has been archived on 2026-10-29. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
WindowsLocationEnable/WindowsLocationServicesON.ps1

30 lines
1.5 KiB
PowerShell

# 1. Close Settings so it re-reads registry values upon opening
Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue
# 2. Set the Master Location switch (the exact UAC-protected toggle)
$overrideKey = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}"
if (-not (Test-Path $overrideKey)) {
New-Item -Path $overrideKey -Force | Out-Null
}
Set-ItemProperty -Path $overrideKey -Name "SensorPermissionState" -Value 1 -Type DWord -Force
# 3. Allow Machine-level location capability
$hklmConsent = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"
if (-not (Test-Path $hklmConsent)) {
New-Item -Path $hklmConsent -Force | Out-Null
}
Set-ItemProperty -Path $hklmConsent -Name "Value" -Value "Allow" -Type String -Force
# 4. Allow User-level location capability for the current profile
$hkcuConsent = "HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"
if (-not (Test-Path $hkcuConsent)) {
New-Item -Path $hkcuConsent -Force | Out-Null
}
Set-ItemProperty -Path $hkcuConsent -Name "Value" -Value "Allow" -Type String -Force
# 5. Enable and start the Geolocation Service (lfsvc)
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc" -Name "Start" -Value 2 -Type DWord -Force
Start-Service -Name "lfsvc" -ErrorAction SilentlyContinue
# 6. Reopen Settings directly to the Location page to view the updated toggle
Start-Process "ms-settings:privacy-location"