The above last 2 solutions deal with COM objects so they can be written in pure VBS or Js, or even hybrid batch-VBS/Js. To get the path reliably you'll need to call this by running the below command in PowerShell ::GetFolderPath(::Desktop)Īlternatively you can run this in PowerShell (New-Object –ComObject Shell.Application).namespace(0x10).Self.PathĠx10 here is the Shell Special Folder Constant for desktopĪnother PowerShell way: $c = New-Object -ComObject Wscript.Shell See %USERPROFILE%/Desktop no longer valid after relocating Desktop folder to OneDrive And even the OneDrive folder path can be changed Nowadays Windows tend to enable OneDrive backup by default and user special folders will not be in the user's home path anymore. Even Windows could be installed into a different folder/drive than C:\Windows and Program Files can be changed.
Special folders can be moved around easily, that's why there are registry entries for them, otherwise we'd just need to hard code them everywhere. %UserProfile%\Desktop is wrong!!! Never use it