Category filter
Script to turn on/off location services for apps on Windows
As an IT administrator, you may need to enable or disable location services for all apps on company-owned devices to ensure compliance with your organization’s security and privacy policies. For instance, you may need to install or have already installed apps on your devices that require location access to render their services. To ensure these apps work properly on corporate devices, it is important to prevent users from denying access to the location. Alternatively, you may want to prevent apps on your devices from accessing locations to improve organizational security. You will need to restrict users from granting location services in such cases. Regardless of the requirement, you can employ Hexnode’s Execute Custom Script action to forcefully turn on/off location services for apps on your Windows devices.
Allow apps to access location services
Run the below script to allow all apps to access location services. Once the script is executed, users cannot make changes denying apps access to location services.
Batch Script
1 |
reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy /v LetAppsAccessLocation /t REG_DWORD /d 1 /f |
PowerShell Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$Name = "LetAppsAccessLocation" $Value = 1 $Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy" If ((Test-Path $Path) -eq $false){ New-Item -Path $Path -ItemType Directory } If (-!(Get-ItemProperty -Path $Path -Name $name -ErrorAction SilentlyContinue)){ New-ItemProperty -Path $Path -Name $Name -Value $Value } else{ Set-ItemProperty -Path $Path -Name $Name -Value $Value } |
Once the script is executed successfully, you can see the toggle button turned on and greyed out:
Deny apps access to location services
Run the below script to forcefully deny all apps from accessing location services. Once the script is executed, users cannot make changes that allow apps to access the location services.
Batch Script
1 |
reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy /v LetAppsAccessLocation /t REG_DWORD /d 2 /f |
PowerShell Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$Name = "LetAppsAccessLocation" $Value = 2 $Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy" If ((Test-Path $Path) -eq $false){ New-Item -Path $Path -ItemType Directory } If (-!(Get-ItemProperty -Path $Path -Name $name -ErrorAction SilentlyContinue)){ New-ItemProperty -Path $Path -Name $Name -Value $Value } else{ Set-ItemProperty -Path $Path -Name $Name -Value $Value } |
Once the script is executed successfully, you can see the toggle button turned off and greyed out: