alex_bn_lee

导航

[1118] Change Shortcut Target Using a Batch File

Steps to Change Shortcut Target Using a Batch File:

  1. Create a Batch File:

    • Open Notepad.

    • Write the following code in Notepad:

      @echo off
      set "shortcutPath=C:\Path\to\your\shortcut.lnk"
      set "newTargetPath=C:\New\Path\to\your\file.exe"
      
      set "tempVbs=%temp%\shortcut.vbs"
      
      echo Set oWS = WScript.CreateObject("WScript.Shell") > "%tempVbs%"
      echo Set oLink = oWS.CreateShortcut("%shortcutPath%") >> "%tempVbs%"
      echo oLink.TargetPath = "%newTargetPath%" >> "%tempVbs%"
      echo oLink.Save >> "%tempVbs%"
      
      cscript //nologo "%tempVbs%"
      del "%tempVbs%"
      
    • Replace C:\Path\to\your\shortcut.lnk with the path to your shortcut file.

    • Replace C:\New\Path\to\your\file.exe with the new target path you want to set.

  2. Save the Batch File:

    • Save the file with a .bat extension, for example, change_shortcut_target.bat.
  3. Run the Batch File:

    • Double-click the batch file to run it. This will execute the script and change the target path of the specified shortcut.

Explanation:

  • set "shortcutPath=...": Defines the path to the shortcut file.
  • set "newTargetPath=...": Defines the new target path for the shortcut.
  • set "tempVbs=%temp%\shortcut.vbs": Creates a temporary VBScript file.
  • echo ... > "%tempVbs%": Writes the VBScript code to the temporary file.
  • cscript //nologo "%tempVbs%": Runs the VBScript to modify the shortcut.
  • del "%tempVbs%": Deletes the temporary VBScript file.

This method uses a combination of batch scripting and VBScript to change the target of the shortcut.

If you have any further questions or need additional assistance, feel free to ask! 😊

posted on 2025-03-07 14:07  McDelfino  阅读(37)  评论(0)    收藏  举报