I created a batch file that searches for the users desktop folder in Windows.
for /F "skip=2 tokens=3* delims= " %%a in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop') do set DESKTOP=%%a
If my desktop folder isn't in C:\Users\User\Desktop, it will work and return the correct folder, for example in my case E:\User\Desktop. If the desktop folder is in C:\Users\User\Desktop, the script above will result into %USERPROFILE%\Desktop. Later in the script I try to create a new file on desktop. In the first option it will work, because E:\User\Desktop is a real directory. In the second one it won't because obviously %USERPROFILE%\Desktop doesn't count as a directory.
echo start javaw -jar "path/to/program.jar" >"%DESKTOP%\Start program.bat"
How to get it work on both situations?
Doing
if /I "%DESKTOP%" EQU "%USERPROFILE%\Desktop"
doesn't help because it is the same as
if /I "%DESKTOP%" EQU "C:\Users\User\Desktop"