%USERPROFILE%/Desktop no longer valid after relocating Desktop folder to OneDrive

5.7k views Asked by At

I've moved my Windows 10's /Desktop folder to a different location.

Desktop properties

As a result, my batch and Powershell scripts that were pointing to %USERPROFILE%/Desktop no longer worked. Is there another way to get the location of my desktop without hardcoding the new path in?

1

There are 1 answers

1
phuclv On BEST ANSWER

In PowerShell you can use this

[Environment]::GetFolderPath([Environment+SpecialFolder]::Desktop)

To use it from a batch file you can call powershell to get the path

powershell -C "[Environment]::GetFolderPath([Environment+SpecialFolder]::Desktop)"

and then save the result to a variable using for /f