Skip to content

Enable Windows Location Services

directorcia edited this page Dec 3, 2025 · 1 revision

Enable Windows Location Services

This document explains the execution, parameters, operations, changes, and troubleshooting for the PowerShell script enable-location-services.ps1.

  • Requires: Run PowerShell as Administrator
  • OS: Windows
  • Output: Console messages (optional), transcript file in C:\Temp when -Silent is used

Purpose

Enable Windows Location Services system-wide and for the current user:

  • Start and set Geolocation Service (lfsvc) to Automatic
  • Clear any policy that disables location
  • Set system flag to turn Location Services ON
  • Enable user-level app capability for location
  • Optional reboot and optional silent transcript logging

Parameters

  • -ForceReboot: Reboots the machine after changes are applied
  • -Silent: Suppresses console output and writes a transcript to C:\Temp\location-enable.log

Exit codes:

  • 0: Success (may include non-fatal warnings)
  • 10: Service configuration failure (lfsvc)
  • 20: Policy update failure (HKLM policy)
  • 30: Registry configuration status failure (system toggle)
  • 40: User consent failure (HKCU capability)

Execution Flow

  1. Admin Rights Check
  • Verifies the process is elevated using WindowsPrincipal
  • If not administrator, script terminates with error guidance
  1. Optional Silent Transcript
  • If -Silent:
    • Ensures C:\Temp exists
    • Starts transcript C:\Temp\location-enable.log (append mode)
    • Suppresses Write-Host messages; warnings/errors still recorded
  1. Geolocation Service (lfsvc)
  • Get-Service lfsvc
  • If StartupType != Automatic:
    • Set-Service -StartupType Automatic
  • If Status != Running:
    • Start-Service lfsvc
  • On failure:
    • Warn and set exit code 10 (continues processing)
  1. Clear Group Policy that disables location
  • Path: HKLM:\SOFTWARE\Policies\Microsoft\Windows\Location
  • Value: DisableLocation (DWORD)
  • If present, set DisableLocation=0 (enables location)
  • On failure:
    • Warn and set exit code 20 (continues processing)
  1. Enable system Location Services flag
  • Path: HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration
  • Value: Status (DWORD, 1=On, 0=Off)
  • Ensures key exists, sets Status=1
  • On failure:
    • Warn and set exit code 30 (continues processing)
  1. Allow user-level location capability
  • Path: HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location
  • Value: Value (String, 'Allow')
  • Ensures path exists, sets Value='Allow'
  • On failure:
    • Warn and set exit code 40 (continues processing)
  1. Final Output and Reboot
  • If not -Silent: prints success guidance and suggests sign-out/in or reboot if the toggle remains Off
  • If -ForceReboot:
    • Optional countdown, stops transcript, Restart-Computer -Force
  • Else:
    • Stops transcript (if any), exits with accumulated exit code

What Gets Changed

  • Service lfsvc (Geolocation Service)

    • StartupType: Automatic
    • Status: Running
  • Policy override (HKLM)

    • HKLM:\SOFTWARE\Policies\Microsoft\Windows\Location\DisableLocation = 0 (if present)
  • System configuration (HKLM)

    • HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration\Status = 1
  • User capability (HKCU)

    • HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location\Value = 'Allow'

Usage

Run PowerShell as Administrator.

Clone this wiki locally