Update WindowsLocationServicesON.ps1

This commit is contained in:
CristianD committed 2026-10-29 16:41:17 +00:00
1 parent 06e9c4380a
commit 4274617657
1 file changed
+25 -44
+25 -44
View File
@@ -1,52 +1,33 @@
# 1. Stop the service first to release any file locks # 1. Kill the Settings app completely so it re-queries state on open
Stop-Service -Name "lfsvc" -Force -ErrorAction SilentlyContinue Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue
# 2. Configure lfsvc registry startup type directly (2 = Automatic) # 2. Fix the Geolocation service dependencies and permissions
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc" -Name "Start" -Value 2 -Type DWord -Force sc.exe config RpcSs start= auto
sc.exe start RpcSs
# 3. Ensure the service host parameters are properly mapped sc.exe config lfsvc start= auto
New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" -Force | Out-Null sc.exe start lfsvc
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" -Name "Status" -Value 1 -Type DWord -Force
# 4. Remove all Group Policy & MDM location restrictions # 3. Force the Location Broker Configuration and Consent Flags
$policyPaths = @( $regTweaks = @(
"HKLM:\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors", # Master switch registry path for Windows 11
"HKCU:\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors", @{ Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"; Name = "Value"; Value = "Allow"; Type = "String" },
"HKLM:\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy", @{ Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"; Name = "Value"; Value = "Allow"; Type = "String" },
"HKCU:\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy" # 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 ($path in $policyPaths) { foreach ($tweak in $regTweaks) {
if (Test-Path $path) { if (-not (Test-Path $tweak.Path)) {
Remove-ItemProperty -Path $path -Name "DisableLocation" -ErrorAction SilentlyContinue New-Item -Path $tweak.Path -Force | Out-Null
Remove-ItemProperty -Path $path -Name "DisableLocationScripting" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $path -Name "DisableSensors" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $path -Name "LetAppsAccessLocation" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $path -Name "LetAppsAccessLocation_UserInControlOfTheseApps" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $path -Name "LetAppsAccessLocation_ForceAllowTheseApps" -ErrorAction SilentlyContinue
} }
Set-ItemProperty -Path $tweak.Path -Name $tweak.Name -Value $tweak.Value -Type $tweak.Type -Force
} }
# 5. Reset master capability consent keys # 4. Restart Explorer and launch Settings directly back to Location
$consentPaths = @( Stop-Process -Name "explorer" -Force
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location", Start-Process "ms-settings:privacy-location"
"HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"
)
foreach ($path in $consentPaths) {
if (-not (Test-Path $path)) {
New-Item -Path $path -Force | Out-Null
}
Set-ItemProperty -Path $path -Name "Value" -Value "Allow" -Type String -Force
}
# 6. Enable Windows Sensor platform permissions
$sensorGuid = "{BFA794E4-F964-4FDB-90F6-51056BFE4B44}"
$sensorPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Permissions\$sensorGuid"
if (-not (Test-Path $sensorPath)) {
New-Item -Path $sensorPath -Force | Out-Null
}
Set-ItemProperty -Path $sensorPath -Name "SensorPermissionState" -Value 1 -Type DWord -Force
# 7. Start the service
Start-Service -Name "lfsvc"