diff --git a/WindowsLocationServicesON.ps1 b/WindowsLocationServicesON.ps1 index 9fbfa8f..23e80b7 100644 --- a/WindowsLocationServicesON.ps1 +++ b/WindowsLocationServicesON.ps1 @@ -1,27 +1,28 @@ -# 1. Terminate Settings app to allow clean reload +# 1. Kill Settings app so it doesn't hold the UI state in memory Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue -# 2. Configure and start lfsvc service +# 2. Make sure lfsvc is running sc.exe config lfsvc start= auto sc.exe start lfsvc -# 3. Enable Master Machine Location Access (HKLM) -reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" /v "Value" /t REG_SZ /d "Allow" /f +# 3. Call the Windows.System.SystemLocationAccess WinRT API directly +[Windows.System.SystemLocationAccess, Windows.System, ContentType = WindowsRuntime] | Out-Null +$asyncOp = [Windows.System.SystemLocationAccess]::RequestAccessAsync() -# 4. Enable User Profile Location Access (HKCU) +# 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. Enable internal service configuration flag -reg.exe add "HKLM\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" /v "Status" /t REG_DWORD /d 1 /f +# 5. Restart lfsvc to reload the state +Restart-Service -Name "lfsvc" -Force -# 6. Enable Windows Sensor platform permissions -reg.exe add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Permissions\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}" /v "SensorPermissionState" /t REG_DWORD /d 1 /f - -# 7. Remove Group Policy overrides if present -reg.exe delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors" /v "DisableLocation" /f 2>$null -reg.exe delete "HKCU\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors" /v "DisableLocation" /f 2>$null -reg.exe delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors" /v "DisableLocationScripting" /f 2>$null -reg.exe delete "HKCU\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors" /v "DisableLocationScripting" /f 2>$null - -# 8. Restart service to apply immediately -Restart-Service -Name "lfsvc" -Force \ No newline at end of file +# 6. Reopen Settings directly to the Location page +Start-Process "ms-settings:privacy-location" \ No newline at end of file