Get desktop path from a batch fileTag(s): Misc Prog HowTo
From a CMD, we launch a one-liner PowerShell script, capture its output to initialize an environment variable and we create a textfile on the desktop.
@echo off SETLOCAL FOR /F "usebackq" %%f IN (`PowerShell -NoProfile -Command "Write-Host([Environment]::GetFolderPath('Desktop'))"`) DO ( SET "DESKTOP_FOLDER=%%f" ) echo Hello World > %DESKTOP_FOLDER%\realhowto.txt @ECHO %DESKTOP_FOLDER%