Archived
Update WindowsLocationServicesON.ps1
This commit is contained in:
1 parent
3a72e64cc7
commit
67e138036c
1 file changed
+38
-21
@@ -1,26 +1,43 @@
|
|||||||
# 1. Terminate the Settings app process so it clears its cache
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Enables Windows Master Location Services and app-level location access.
|
||||||
|
#>
|
||||||
|
|
||||||
|
# 1. Close Settings app to force a UI refresh when reopened
|
||||||
Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue
|
Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# 2. Set HKLM Device-wide consent
|
# 2. Configure and start the Geolocation Service (lfsvc)
|
||||||
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" -Force | Out-Null
|
Write-Output "Configuring Geolocation service (lfsvc)..."
|
||||||
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" -Name "Value" -Value "Allow" -Type String -Force
|
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc" -Name "Start" -Value 2 -Type DWord -Force
|
||||||
|
Start-Service -Name "lfsvc" -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# 3. Set the Geolocation service operational status flag to Active (1)
|
# 3. Set service configuration status flag
|
||||||
New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" -Force | Out-Null
|
$svcConfigPath = "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration"
|
||||||
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" -Name "Status" -Value 1 -Type DWord -Force
|
if (-not (Test-Path $svcConfigPath)) { New-Item -Path$svcConfigPath -Force | Out-Null }
|
||||||
|
Set-ItemProperty -Path $svcConfigPath -Name "Status" -Value 1 -Type DWord -Force
|
||||||
|
|
||||||
|
# 4. Remove any conflicting local policies
|
||||||
|
$policyPaths = @(
|
||||||
|
"HKLM:\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors",
|
||||||
|
"HKCU:\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors"
|
||||||
|
)
|
||||||
|
foreach ($path in$policyPaths) {
|
||||||
|
if (Test-Path $path) {
|
||||||
|
Remove-ItemProperty -Path $path -Name "DisableLocation" -ErrorAction SilentlyContinue
|
||||||
|
Remove-ItemProperty -Path $path -Name "DisableLocationScripting" -ErrorAction SilentlyContinue
|
||||||
|
Remove-ItemProperty -Path $path -Name "DisableSensors" -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 5. Enable Master Device-Level Location Switch (HKLM)
|
||||||
|
$hklmConsentPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"
|
||||||
|
if (-not (Test-Path $hklmConsentPath)) { New-Item -Path$hklmConsentPath -Force | Out-Null }
|
||||||
|
Set-ItemProperty -Path $hklmConsentPath -Name "Value" -Value "Allow" -Type String -Force
|
||||||
|
|
||||||
|
# 6. Enable User-Level Location Switch (HKCU and all loaded user hives)
|
||||||
|
$hkcuConsentPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"
|
||||||
|
if (-not (Test-Path $hkcuConsentPath)) { New-Item -Path$hkcuConsentPath -Force | Out-Null }
|
||||||
|
Set-ItemProperty -Path $hkcuConsentPath -Name "Value" -Value "Allow" -Type String -Force
|
||||||
|
|
||||||
# 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+$" }
|
$userSids = Get-ChildItem "Registry::HKEY_USERS" | Where-Object { $_.PSChildName -match "^S-1-5-21-\d+-\d+-\d+-\d+$" }
|
||||||
foreach ($sid in $userSids) {
|
foreach ($sid in$user`
|
||||||
$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 $targetPath -Name "Value" -Value "Allow" -Type String -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