I want my .bat script (test.bat) to create a shortcut to itself so that I can copy it to my windows 8 Startup folder.
I have written this line of code to copy the file but I haven't yet found a way to create the said shortcut, as you can see it only copies the script.
xcopy "C:\Users\Gabriel\Desktop\test.bat" "C:\Users\Gabriel\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
Can you help me out?
Rohit Sahu's answer worked best for me in Windows 10. The PowerShell solution ran, but no shortcut appeared. The JScript solution gave me syntax errors. I didn't try mklink, since I didn't want to mess with permissions.
I wanted the shortcut to appear on the desktop. But I also needed to set the icon, the description, and the working directory. Note that MyApp48.bmp is a 48x48 pixel image. Here's my mod of Rohit's solution:
link.vbs
command
Cannot be done with pure batch.Check the shortcutJS.bat - it is a
jscript/bat
hybrid and should be used with.bat
extension:With
-help
you can check the other options (you can set icon , admin permissions and etc.)You could use a PowerShell command. Stick this in your batch script and it'll create a shortcut to
%~f0
in%userprofile%\Start Menu\Programs\Startup
:If you prefer not to use PowerShell, you could use
mklink
to make a symbolic link. Syntax:See
mklink /?
in a console window for full syntax, and this web page for further information.In your batch script, do:
The shortcut created isn't a traditional .lnk file, but it should work the same nevertheless. Be advised that this will only work if the .bat file is run from the same drive as your startup folder. Also, apparently admin rights are required to create symbolic links.
I present a small hybrid script [BAT/VBS] to create a desktop shortcut. And you can of course modifie it to your purpose.
The best way is to run this batch file. open notepad and type:-
Save as filename.bat(be careful while saving select all file types) worked well in win XP.