Archived
Update WindowsLocationServicesON.ps1
This commit is contained in:
1 parent
4274617657
commit
3a72e64cc7
1 file changed
+18
-25
@@ -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"
|
||||
Reference in new issue
Block a user