How to Create a Shortcut for a Batch File
- PowerShell Command to Create a Shortcut to Batch File
-
mklink
Command to Create a Shortcut to Batch File
This article discusses various methods to create a shortcut for a Batch file on Windows. We will cover two distinct methods we use to make a Batch script create a shortcut in our Windows Startup
folder.
PowerShell Command to Create a Shortcut to Batch File
We can slap a PowerShell command into our Batch file to create shortcuts. For example, if we stick the command below at the end of our Batch scripts, it will send a shortcut of itself to our Startup
folder.
powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Start Menu\Programs\Startup\%~n0.lnk');$s.TargetPath='%~f0';$s.Save()"
If you do not want to use PowerShell, you can use mklink
.
mklink
Command to Create a Shortcut to Batch File
We can use mklink
to create a symbolic link. Below is the basic syntax of the command.
mklink saveShortcutAs targetOfShortcut
In our case, we will add the following to our Batch script.
mklink "%userprofile%\Start Menu\Programs\Startup\%~nx0" "%~f0"
Although the produced shortcut is not a standard .lnk
file, it should still function as intended. Please note that for this to function, the .bat
file must be launched from the same drive as your Startup
folder.
Additionally, it appears that creating symbolic links requires admin privileges.
In conclusion, you can send a shortcut of a Batch script to your Startup
folder using any of the methods discussed above.
John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
LinkedIn