0

I want to start with a little disclaimer: I read this thread on a similar issue to mine, but it seems like the solution doesn't work. It might just be me not understanding it completely but here I am asking for clarification.

My goal is to copy a shortcut to the start menu programs folder conserving all of its attributes, icon and start in value. I thought making a copy would be simple but it seems like my brain can't understand anything today.

So here's the actual xcopy argument:

@echo off
xcopy "%~dp0\file.lnk" "%userprofile%\Start Menu\Programs\file.lnk\" /p /v /f
pause

I have tried every combination of adding/removing the file name, with/without the \ at the end and any combination of both... I also tried running the batch file as administrator just in case.

The @echo off is just a habit and the pause is to allow me to read any error messages that could pop up. I also put the extra arguments into the xcopy line to try to get more information. It doesn't seem to help me a lot though.

I'm starting to think the issue is completely isolated from the other thread.

Spyro 999
  • 27
  • 2
  • 11
  • Are you positive that `%userprofile%\Start Menu\Programs` exists? Like running `dir "%userprofile%\Start Menu\Programs"` in the command prompt actually returns something? Later versions of Windows moved it to `%AppData%\Microsoft\Windows\Start Menu\Programs` instead. – SomethingDark Mar 15 '22 at 03:39
  • Seems you're using point, click and giggle. Is `%~dp0` what you think it should be? I'd suggest a line `echo "%cd%" vs "%~dp0"` displayed before the `xcopy` might reveal something of interest, and does the sourcefile exist? – Magoo Mar 15 '22 at 05:16
  • The source file indeed exists and I will try both of tour ideas in the next hour. However putting the link I used in win+r worked for me... – Spyro 999 Mar 15 '22 at 11:50
  • Please note that `%~dp0` expands to a path always ending with a backslash and therefore `"%~dp0\file.lnk"` is of not correct syntax as resulting in two backslashes in fully qualified file name which the Windows I/O functions correct to a single backslash before passing the file name string to the file system. So use `"%~dp0file.lnk"` in your batch file to define source 100% correct. The backslash at end of your destination argument is of course also not correct, but you fixed that already as it can be seen in your answer. – Mofi Mar 15 '22 at 16:39

1 Answers1

0

As suggested by SomethingDark, changing the path from %userprofile%\Start Menu\Programs\ to %AppData%\Microsoft\Windows\Start Menu\Programs\ fixed my issue.

Spyro 999
  • 27
  • 2
  • 11
  • Which versions of Windows should be supported by your batch file? ``%AppData%\Microsoft\Windows\Start Menu\Programs\`` is correct only for Windows Vista and newer Windows versions. On Windows XP and older Windows versions the command __XCOPY__ works also and creates the entire directory tree as specified in the batch file, but the the shortcut file is copied to the wrong folder in this case. For example the user's start menu on a German Windows XP is by default: ``C:\Dokumente und Einstellungen\%USERNAME%\Startmenü\Programme\`` (not on my German Windows XP as I changed this user shell folder). – Mofi Mar 15 '22 at 16:46
  • See my answer on [path of user desktop in batch files](https://stackoverflow.com/a/69602421/3074564). The batch file code in this answer can be easily rewritten to query the folder path of the user shell folder `Start Menu` instead of the user shell folder `Desktop` to get the full path to really used user's start menu folder instead of hoping the default folder path for Windows Vista and newer Windows versions works on all Windows PCs on which this batch file is ever executed in future. – Mofi Mar 15 '22 at 16:53
  • PS: On my German Windows XP I modified the `Start Menu` in registry value to `C:\Settings\%USERNAME%\Startmenü\Programme` and all applications installed ever by me on my German Windows XP read the custom start menu path correct from Windows registry and created the shortcut files correct in this folder or a subfolder of it. The documents folder is on all my Windows computers on a completely different drive as I separate system files from user files by using different drives which makes backups easier and managing the user files. – Mofi Mar 15 '22 at 16:56