Archived
Update WindowsLocationServicesON.ps1
This commit is contained in:
1 parent
c8f7859edf
commit
816e3a159a
1 file changed
+22
-20
@@ -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
|
Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# 2. Make sure lfsvc is running
|
# 2. Set the Master Location switch (the exact UAC-protected toggle)
|
||||||
sc.exe config lfsvc start= auto
|
$overrideKey = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}"
|
||||||
sc.exe start lfsvc
|
if (-not (Test-Path $overrideKey)) {
|
||||||
|
New-Item -Path $overrideKey -Force | Out-Null
|
||||||
# 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
|
|
||||||
}
|
}
|
||||||
|
Set-ItemProperty -Path $overrideKey -Name "SensorPermissionState" -Value 1 -Type DWord -Force
|
||||||
|
|
||||||
$result = $asyncOp.GetResults()
|
# 3. Allow Machine-level location capability
|
||||||
Write-Host "System Location Access Result: $result"
|
$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
|
# 4. Allow User-level location capability for the current profile
|
||||||
reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" /v "Value" /t REG_SZ /d "Allow" /f
|
$hkcuConsent = "HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"
|
||||||
reg.exe add "HKCU\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" /v "Value" /t REG_SZ /d "Allow" /f
|
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
|
# 5. Enable and start the Geolocation Service (lfsvc)
|
||||||
Restart-Service -Name "lfsvc" -Force
|
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"
|
Start-Process "ms-settings:privacy-location"
|
||||||
Reference in new issue
Block a user