Albert MN.
Albert MN.

Reputation: 730

Create shortcut in Bat or VBS

I have been struggeling with creating shortcuts for my program/batch file... I want to do it in batch, creating a VBS file doing it, since (at least I think) batch can't create shortcuts... But since I am not at all familiare with VBS coding I have no clue how to do it at all.

But I know how I want it to be. I am kind of looking for a code that I can just put the file name and location in, and it works :3 As I am competely disabled at vbs, I won't understand anything too hard.

Thanks in advance :)

Upvotes: 1

Views: 5102

Answers (2)

moffeltje
moffeltje

Reputation: 4669

To elaborate this answer for you to understand it;

Make a text file on your desktop and copy/paste this text:

@echo off

set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"

echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%USERPROFILE%\Desktop\myshortcut.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "D:\myfile.extension" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%

cscript /nologo %SCRIPT%
del %SCRIPT%

Change the myshortcut.lnk in "%USERPROFILE%\Desktop\myshortcut.lnk" to the name you want your shortcut to have (for example "%USERPROFILE%\Desktop\iversenFiles.lnk").

Change "D:\myfile.extension" to the location you want your shortcut to have (for example "C:\iversen\Documents\iversen.txt").

Save the file and change it's extension from .txt to .bat

Double click it.

Upvotes: 0

Hackoo
Hackoo

Reputation: 18857

I present a small hybrid script [BAT/VBS] to create a desktop shortcut. So this script shows you how to create a shortcut on the desktop to the calculator.

@echo off
mode con cols=87 lines=5 & color 9B
Title Generer le vbscript pour la creation du raccourci sur le bureau by Hackoo
echo Generer le vbscript pour la creation du raccourci
Timeout /T 2 > Nul
(
echo Call Shortcut("c:\windows\system32\calc.exe","Calculatrice"^)
echo ^'**********************************************************************************************^)
echo Sub Shortcut(CheminApplication,Nom^)
echo    Dim objShell,DesktopPath,objShortCut,MyTab
echo    Set objShell = CreateObject("WScript.Shell"^)
echo    MyTab = Split^(CheminApplication,"\"^)
echo    If Nom = "" Then
echo    Nom = MyTab(UBound^(MyTab^)^)
echo    End if
echo    DesktopPath = objShell.SpecialFolders("Desktop"^)
echo    Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Nom ^& ".lnk"^)
echo    objShortCut.TargetPath = Dblquote^(CheminApplication^)
echo    ObjShortCut.IconLocation = "Winver.exe,0"
echo    objShortCut.Save
echo End Sub
echo ^'**********************************************************************************************
echo ^'Fonction pour ajouter les doubles quotes dans une variable
echo Function DblQuote(Str^)
echo    DblQuote = Chr(34^) ^& Str ^& Chr^(34^)
echo End Function
echo ^'**********************************************************************************************
) > Shortcutme.vbs
echo Execution du vbscript pour la creation du raccourci de la calculatrice sur le bureau
Start /Wait Shortcutme.vbs
echo Suppression du Vbscript
Del Shortcutme.vbs
echo Termine
Pause > Nul

Upvotes: 1

Related Questions