From 1142ad9ff7ee0d641e6e2f29732cd88d84bfd70d Mon Sep 17 00:00:00 2001 From: CristianD Date: Thu, 29 Oct 2026 16:46:02 +0000 Subject: [PATCH] Update WindowsLocationServicesON.ps1 --- WindowsLocationServicesON.ps1 | 56 +++++++++++++---------------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/WindowsLocationServicesON.ps1 b/WindowsLocationServicesON.ps1 index 7b2d3e6..9fbfa8f 100644 --- a/WindowsLocationServicesON.ps1 +++ b/WindowsLocationServicesON.ps1 @@ -1,43 +1,27 @@ -<# -.SYNOPSIS - Enables Windows Master Location Services and app-level location access. -#> - -# 1. Close Settings app to force a UI refresh when reopened +# 1. Terminate Settings app to allow clean reload Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue -# 2. Configure and start the Geolocation Service (lfsvc) -Write-Output "Configuring Geolocation service (lfsvc)..." -Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc" -Name "Start" -Value 2 -Type DWord -Force -Start-Service -Name "lfsvc" -ErrorAction SilentlyContinue +# 2. Configure and start lfsvc service +sc.exe config lfsvc start= auto +sc.exe start lfsvc -# 3. Set service configuration status flag -$svcConfigPath = "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" -if (-not (Test-Path $svcConfigPath)) { New-Item -Path$svcConfigPath -Force | Out-Null } -Set-ItemProperty -Path $svcConfigPath -Name "Status" -Value 1 -Type DWord -Force +# 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 -# 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 - } -} +# 4. Enable User Profile Location Access (HKCU) +reg.exe add "HKCU\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" /v "Value" /t REG_SZ /d "Allow" /f -# 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 +# 5. Enable internal service configuration flag +reg.exe add "HKLM\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" /v "Status" /t REG_DWORD /d 1 /f -# 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 +# 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 -$userSids = Get-ChildItem "Registry::HKEY_USERS" | Where-Object { $_.PSChildName -match "^S-1-5-21-\d+-\d+-\d+-\d+$" } -foreach ($sid in$user` \ No newline at end of file +# 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