Update WindowsLocationServicesON.ps1

This commit is contained in:
CristianD committed 2026-10-29 16:42:53 +00:00
1 parent 4274617657
commit 3a72e64cc7
1 file changed
+18 -25
+18 -25
View File
@@ -1,33 +1,26 @@
# 1. Kill the Settings app completely so it re-queries state on open # 1. Terminate the Settings app process so it clears its cache
Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue
# 2. Fix the Geolocation service dependencies and permissions # 2. Set HKLM Device-wide consent
sc.exe config RpcSs start= auto New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" -Force | Out-Null
sc.exe start RpcSs Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" -Name "Value" -Value "Allow" -Type String -Force
sc.exe config lfsvc start= auto # 3. Set the Geolocation service operational status flag to Active (1)
sc.exe start lfsvc New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" -Force | Out-Null
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" -Name "Status" -Value 1 -Type DWord -Force
# 3. Force the Location Broker Configuration and Consent Flags # 4. Set HKCU User consent for all active user hives on the machine
$regTweaks = @( $userSids = Get-ChildItem "Registry::HKEY_USERS" | Where-Object { $_.PSChildName -match "^S-1-5-21-\d+-\d+-\d+-\d+$" }
# Master switch registry path for Windows 11 foreach ($sid in $userSids) {
@{ Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"; Name = "Value"; Value = "Allow"; Type = "String" }, $targetPath = "Registry::HKEY_USERS\$($sid.PSChildName)\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"
@{ Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"; Name = "Value"; Value = "Allow"; Type = "String" }, if (-not (Test-Path $targetPath)) {
# Sensor system permissions New-Item -Path $targetPath -Force | Out-Null
@{ Path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Permissions\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}"; Name = "SensorPermissionState"; Value = 1; Type = "DWord" },
# Geolocation internal provider state
@{ Path = "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration"; Name = "Status"; Value = 1; Type = "DWord" },
# Clear MDM/Policy blocks if present
@{ Path = "HKLM:\SOFTWARE\Microsoft\PolicyManager\default\System\AllowLocation"; Name = "value"; Value = 1; Type = "DWord" }
)
foreach ($tweak in $regTweaks) {
if (-not (Test-Path $tweak.Path)) {
New-Item -Path $tweak.Path -Force | Out-Null
} }
Set-ItemProperty -Path $tweak.Path -Name $tweak.Name -Value $tweak.Value -Type $tweak.Type -Force Set-ItemProperty -Path $targetPath -Name "Value" -Value "Allow" -Type String -Force
} }
# 4. Restart Explorer and launch Settings directly back to Location # 5. Restart the Geolocation service cleanly to reload registry state
Stop-Process -Name "explorer" -Force Restart-Service -Name "lfsvc" -Force
# 6. Re-open the Location Settings page
Start-Process "ms-settings:privacy-location" Start-Process "ms-settings:privacy-location"