This repository has been archived on 2026-10-29. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
WindowsLocationEnable/WindowsLocationServicesON.ps1
T

28 lines
1.2 KiB
PowerShell

# 1. Kill Settings app so it doesn't hold the UI state in memory
Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue
# 2. Make sure lfsvc is running
sc.exe config lfsvc start= auto
sc.exe start lfsvc
# 3. Call the Windows.System.SystemLocationAccess WinRT API directly
[Windows.System.SystemLocationAccess, Windows.System, ContentType = WindowsRuntime] | Out-Null
$asyncOp = [Windows.System.SystemLocationAccess]::RequestAccessAsync()
# Wait for the async task to complete
while ($asyncOp.Status -eq [Windows.Foundation.AsyncStatus]::Started) {
Start-Sleep -Milliseconds 100
}
$result = $asyncOp.GetResults()
Write-Host "System Location Access Result: $result"
# 4. Set both Machine and User Consent Store keys
reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" /v "Value" /t REG_SZ /d "Allow" /f
reg.exe add "HKCU\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" /v "Value" /t REG_SZ /d "Allow" /f
# 5. Restart lfsvc to reload the state
Restart-Service -Name "lfsvc" -Force
# 6. Reopen Settings directly to the Location page
Start-Process "ms-settings:privacy-location"