Clear OneDrive environment variable
- Single actionThis page belongs to a script, containing basic changes to achieve a task.
- Windows onlyThis script improves your privacy on Windows
- Impact: MediumSystem Functionality Loss Risk: Moderate
This action improves privacy with minimal impact when you run the recommended script.
This action improves privacy with some impact when you run the recommended script. - Batch (batchfile)These changes use Windows system commands to update your settings.
- Fully reversible
You can fully restore this action (revert back to the original behavior) using this website.
The restore/revert methods provided here can help you fix issues.
Overview
Since Windows 10 1809, Microsoft introduced %ONEDRIVE%
environment variable to
reach OneDrive through an alias 1. This variable is redundant when OneDrive is
undesired.
This script deletes OneDrive
environment variable 2.
OneDrive
key at HKCU\Environment
is found on both Windows 10
(since 21H2, missing in 20H2) and Windows 11 (since 23H2).
This script is only recommended if you understand its implications.
Some non-critical or features may no longer function correctly after running this script.
This script can be fully reversed to restore changes if something goes wrong.
Sources
- Determine OneDrive synchronisation folders - Super User. superuser.com. (2024).
Original: https://superuser.com/questions/1336521/determine-onedrive-synchronisation-folders/1397495
Archived: https://web.archive.org/web/20240314091504/https://superuser.com/questions/1336521/determine-onedrive-synchronisation-folders/1397495#1397495 - Export registry value to file and then set a variable in Batch - Stack Overflow. stackoverflow.com. (2025).
Original: https://stackoverflow.com/questions/46744840/export-registry-value-to-file-and-then-set-a-variable-in-batch
Apply Now
Choose one of three ways to apply:
Download script
Download and run the script directly- No app needed
- Offline usage
- Easy-to-apply
- Free
- Open-source
Help
How to apply or restore "Clear OneDrive environment variable" using script
- ≈ 2 min to complete
- Tools: Web Browser
- Difficulty: Simple
- ≈ 5 instructions
- 1
Download
Download the script file by clicking on thebutton above.
Use button above to restore changes. - 2
Keep the file
If warned by your browser, keep the file. - 3
Open
Open the downloaded file. - 4
Exit
Once it's done, press any key to exit the window. - 5
Restart
Restart your computer for all changes to take effect.
Apply with privacy.sexy
Guided, automated application with safety checks- Recommended for most users
- Includes safety checks
- Free
- Open-source
- Popular
- Offline/Online usage
Help
How to apply or restore "Clear OneDrive environment variable" using privacy.sexy
- ≈ 3 min to complete
- Tools: privacy.sexy
- Difficulty: Simple
- ≈ 4 instructions
- 2
Choose script
- Search for the script name: Clear OneDrive environment variable
- Check the script by clicking on the checkbox.
- 3
Run
Click on ▶️ Run button at the bottom of the page.This button only appears on desktop version (recommended). On browser, use 💾 Save button.
- Apply
- Revert
:: Delete the registry value "OneDrive" from the key "HKCU\Environment"
PowerShell -ExecutionPolicy Unrestricted -Command "$keyName = 'HKCU\Environment'; $valueName = 'OneDrive'; $hive = $keyName.Split('\')[0]; $path = "^""$($hive):$($keyName.Substring($hive.Length))"^""; Write-Host "^""Removing the registry value '$valueName' from '$path'."^""; if (-Not (Test-Path -LiteralPath $path)) { Write-Host 'Skipping, no action needed, registry key does not exist.'; Exit 0; }; $existingValueNames = (Get-ItemProperty -LiteralPath $path).PSObject.Properties.Name; if (-Not ($existingValueNames -Contains $valueName)) { Write-Host 'Skipping, no action needed, registry value does not exist.'; Exit 0; }; try { if ($valueName -ieq '(default)') { Write-Host 'Removing the default value.'; $(Get-Item -LiteralPath $path).OpenSubKey('', $true).DeleteValue(''); } else { Remove-ItemProperty -LiteralPath $path -Name $valueName -Force -ErrorAction Stop; }; Write-Host 'Successfully removed the registry value.'; } catch { Write-Error "^""Failed to remove the registry value: $($_.Exception.Message)"^""; }"
Ijo6IFJlc3RvcmUgdGhlIHJlZ2lzdHJ5IHZhbHVlIFwiT25lRHJpdmVcIiBpbiBrZXkgXCJIS0NVXFxFbnZpcm9ubWVudFwiIHRvIGl0cyBvcmlnaW5hbCB2YWx1ZSBcblBvd2VyU2hlbGwgLUV4ZWN1dGlvblBvbGljeSBVbnJlc3RyaWN0ZWQgLUNvbW1hbmQgXCIkZGF0YSA9ICAnJVVTRVJQUk9GSUxFJVxcT25lRHJpdmUnOyAkcmF3VHlwZSA9ICdSRUdfRVhQQU5EX1NaJzsgJHJhd1BhdGggPSAnSEtDVVxcRW52aXJvbm1lbnQnOyAkdmFsdWUgPSAnT25lRHJpdmUnOyAkaGl2ZSA9ICRyYXdQYXRoLlNwbG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