Archived
Update WindowsLocationServicesON.ps1
This commit is contained in:
1 parent
06e9c4380a
commit
4274617657
1 file changed
+25
-44
@@ -1,52 +1,33 @@
|
||||
# 1. Stop the service first to release any file locks
|
||||
Stop-Service -Name "lfsvc" -Force -ErrorAction SilentlyContinue
|
||||
# 1. Kill the Settings app completely so it re-queries state on open
|
||||
Stop-Process -Name "SystemSettings" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
# 2. Configure lfsvc registry startup type directly (2 = Automatic)
|
||||
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc" -Name "Start" -Value 2 -Type DWord -Force
|
||||
# 2. Fix the Geolocation service dependencies and permissions
|
||||
sc.exe config RpcSs start= auto
|
||||
sc.exe start RpcSs
|
||||
|
||||
# 3. Ensure the service host parameters are properly mapped
|
||||
New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" -Force | Out-Null
|
||||
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" -Name "Status" -Value 1 -Type DWord -Force
|
||||
sc.exe config lfsvc start= auto
|
||||
sc.exe start lfsvc
|
||||
|
||||
# 4. Remove all Group Policy & MDM location restrictions
|
||||
$policyPaths = @(
|
||||
"HKLM:\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors",
|
||||
"HKCU:\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors",
|
||||
"HKLM:\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy",
|
||||
"HKCU:\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy"
|
||||
# 3. Force the Location Broker Configuration and Consent Flags
|
||||
$regTweaks = @(
|
||||
# Master switch registry path for Windows 11
|
||||
@{ Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"; Name = "Value"; Value = "Allow"; Type = "String" },
|
||||
@{ Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"; Name = "Value"; Value = "Allow"; Type = "String" },
|
||||
# Sensor system permissions
|
||||
@{ Path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Permissions\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}"; Name = "SensorPermissionState"; Value = 1; Type = "DWord" },
|
||||
# Geolocation internal provider state
|
||||
@{ Path = "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration"; Name = "Status"; Value = 1; Type = "DWord" },
|
||||
# Clear MDM/Policy blocks if present
|
||||
@{ Path = "HKLM:\SOFTWARE\Microsoft\PolicyManager\default\System\AllowLocation"; Name = "value"; Value = 1; Type = "DWord" }
|
||||
)
|
||||
|
||||
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
|
||||
Remove-ItemProperty -Path $path -Name "LetAppsAccessLocation" -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path $path -Name "LetAppsAccessLocation_UserInControlOfTheseApps" -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path $path -Name "LetAppsAccessLocation_ForceAllowTheseApps" -ErrorAction SilentlyContinue
|
||||
foreach ($tweak in $regTweaks) {
|
||||
if (-not (Test-Path $tweak.Path)) {
|
||||
New-Item -Path $tweak.Path -Force | Out-Null
|
||||
}
|
||||
Set-ItemProperty -Path $tweak.Path -Name $tweak.Name -Value $tweak.Value -Type $tweak.Type -Force
|
||||
}
|
||||
|
||||
# 5. Reset master capability consent keys
|
||||
$consentPaths = @(
|
||||
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location",
|
||||
"HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"
|
||||
)
|
||||
|
||||
foreach ($path in $consentPaths) {
|
||||
if (-not (Test-Path $path)) {
|
||||
New-Item -Path $path -Force | Out-Null
|
||||
}
|
||||
Set-ItemProperty -Path $path -Name "Value" -Value "Allow" -Type String -Force
|
||||
}
|
||||
|
||||
# 6. Enable Windows Sensor platform permissions
|
||||
$sensorGuid = "{BFA794E4-F964-4FDB-90F6-51056BFE4B44}"
|
||||
$sensorPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Permissions\$sensorGuid"
|
||||
if (-not (Test-Path $sensorPath)) {
|
||||
New-Item -Path $sensorPath -Force | Out-Null
|
||||
}
|
||||
Set-ItemProperty -Path $sensorPath -Name "SensorPermissionState" -Value 1 -Type DWord -Force
|
||||
|
||||
# 7. Start the service
|
||||
Start-Service -Name "lfsvc"
|
||||
# 4. Restart Explorer and launch Settings directly back to Location
|
||||
Stop-Process -Name "explorer" -Force
|
||||
Start-Process "ms-settings:privacy-location"
|
||||
Reference in new issue
Block a user