CMD to batch duplicate desktop shortcut with arguments (program not installed in same location on all workstations)

  • 8 months ago
Comment

ChatGPT
1 / 1

To duplicate a desktop shortcut with arguments using a batch script in Windows, you can use the copy command to copy the shortcut file and then modify the copied shortcut's properties to include the required arguments. Here's a basic example of how you might achieve this:

  1. Open Notepad or any text editor.
  2. Paste the following code into the text editor:
batch
@echo off

rem Source and destination paths for the shortcut
set "sourceShortcut=%userprofile%\Desktop\OriginalShortcut.lnk"
set "destinationShortcut=%userprofile%\Desktop\NewShortcut.lnk"

rem Copy the original shortcut to the destination
copy "%sourceShortcut%" "%destinationShortcut%"

rem Modify the new shortcut's properties (add arguments)
set "arguments=your_arguments_here"
powershell -Command "$shortcut = (New-Object -ComObject WScript.Shell).CreateShortcut('%destinationShortcut%'); $shortcut.Arguments = '%arguments%'; $shortcut.Save();"
  1. Replace OriginalShortcut.lnk with the name of the original shortcut file on the desktop.
  2. Replace NewShortcut.lnk with the desired name for the new shortcut.
  3. Replace your_arguments_here with the arguments you want to add to the shortcut.
  4. Save the file with a .bat extension, for example, DuplicateShortcut.bat.

Make sure to test this script on a single shortcut to ensure it's working as expected before applying it to multiple shortcuts.

Remember that shortcuts are specific to the user profile, so the %userprofile% environment variable is used to locate the desktop folder for the current user. If you want to duplicate shortcuts for all users, you might need to adjust the paths accordingly.