diff --git a/WindowsLocationServicesON.ps1 b/WindowsLocationServicesON.ps1 index 23e80b7..ee34c45 100644 --- a/WindowsLocationServicesON.ps1 +++ b/WindowsLocationServicesON.ps1 @@ -1,28 +1,30 @@ -# 1. Kill Settings app so it doesn't hold the UI state in memory +# 1. Close Settings so it re-reads registry values upon opening 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 +# 2. Set the Master Location switch (the exact UAC-protected toggle) +$overrideKey = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}" +if (-not (Test-Path $overrideKey)) { + New-Item -Path $overrideKey -Force | Out-Null } +Set-ItemProperty -Path $overrideKey -Name "SensorPermissionState" -Value 1 -Type DWord -Force -$result = $asyncOp.GetResults() -Write-Host "System Location Access Result: $result" +# 3. Allow Machine-level location capability +$hklmConsent = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" +if (-not (Test-Path $hklmConsent)) { + New-Item -Path $hklmConsent -Force | Out-Null +} +Set-ItemProperty -Path $hklmConsent -Name "Value" -Value "Allow" -Type String -Force -# 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 +# 4. Allow User-level location capability for the current profile +$hkcuConsent = "HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" +if (-not (Test-Path $hkcuConsent)) { + New-Item -Path $hkcuConsent -Force | Out-Null +} +Set-ItemProperty -Path $hkcuConsent -Name "Value" -Value "Allow" -Type String -Force -# 5. Restart lfsvc to reload the state -Restart-Service -Name "lfsvc" -Force +# 5. Enable and start the Geolocation Service (lfsvc) +Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc" -Name "Start" -Value 2 -Type DWord -Force +Start-Service -Name "lfsvc" -ErrorAction SilentlyContinue -# 6. Reopen Settings directly to the Location page +# 6. Reopen Settings directly to the Location page to view the updated toggle Start-Process "ms-settings:privacy-location" \ No newline at end of file