Archived
Update WindowsLocationServicesON.ps1
This commit is contained in:
1 parent
1142ad9ff7
commit
c8f7859edf
1 file changed
+19
-18
@@ -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
|
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 config lfsvc start= auto
|
||||||
sc.exe start lfsvc
|
sc.exe start lfsvc
|
||||||
|
|
||||||
# 3. Enable Master Machine Location Access (HKLM)
|
# 3. Call the Windows.System.SystemLocationAccess WinRT API directly
|
||||||
reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" /v "Value" /t REG_SZ /d "Allow" /f
|
[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
|
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
|
# 5. Restart lfsvc to reload the state
|
||||||
reg.exe add "HKLM\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" /v "Status" /t REG_DWORD /d 1 /f
|
|
||||||
|
|
||||||
# 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
|
Restart-Service -Name "lfsvc" -Force
|
||||||
|
|
||||||
|
# 6. Reopen Settings directly to the Location page
|
||||||
|
Start-Process "ms-settings:privacy-location"
|
||||||
Reference in new issue
Block a user