From 3a72e64cc714ec6d224a484f0f9326459d4e8d6a Mon Sep 17 00:00:00 2001 From: CristianD Date: Thu, 29 Oct 2026 16:42:53 +0000 Subject: [PATCH] Update WindowsLocationServicesON.ps1 --- WindowsLocationServicesON.ps1 | 43 +++++++++++++++-------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/WindowsLocationServicesON.ps1 b/WindowsLocationServicesON.ps1 index 31e08f8..e7ee309 100644 --- a/WindowsLocationServicesON.ps1 +++ b/WindowsLocationServicesON.ps1 @@ -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 -# 2. Fix the Geolocation service dependencies and permissions -sc.exe config RpcSs start= auto -sc.exe start RpcSs +# 2. Set HKLM Device-wide consent +New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" -Force | Out-Null +Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" -Name "Value" -Value "Allow" -Type String -Force -sc.exe config lfsvc start= auto -sc.exe start lfsvc +# 3. Set the Geolocation service operational status flag to Active (1) +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 -$regTweaks = @( - # Master switch registry path for Windows 11 - @{ Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"; Name = "Value"; Value = "Allow"; Type = "String" }, - @{ Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"; Name = "Value"; Value = "Allow"; Type = "String" }, - # Sensor system permissions - @{ 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 +# 4. Set HKCU User consent for all active user hives on the machine +$userSids = Get-ChildItem "Registry::HKEY_USERS" | Where-Object { $_.PSChildName -match "^S-1-5-21-\d+-\d+-\d+-\d+$" } +foreach ($sid in $userSids) { + $targetPath = "Registry::HKEY_USERS\$($sid.PSChildName)\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" + if (-not (Test-Path $targetPath)) { + New-Item -Path $targetPath -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 -Stop-Process -Name "explorer" -Force +# 5. Restart the Geolocation service cleanly to reload registry state +Restart-Service -Name "lfsvc" -Force + +# 6. Re-open the Location Settings page Start-Process "ms-settings:privacy-location" \ No newline at end of file