[1118] Change Shortcut Target Using a Batch File
Steps to Change Shortcut Target Using a Batch File:
-
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.lnkwith the path to your shortcut file. -
Replace
C:\New\Path\to\your\file.exewith the new target path you want to set.
-
-
Save the Batch File:
- Save the file with a
.batextension, for example,change_shortcut_target.bat.
- Save the file with a
-
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! 😊
浙公网安备 33010602011771号