Create a shortcut via batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
LiveITA
Posts: 12
Joined: 25 Jan 2018 14:22

Create a shortcut via batch file

#1 Post by LiveITA » 25 Jan 2018 14:44

Hi guys
I'm making a batch to install a program I made but I'm having an hard time to create a shortcut. I want to autostart the program at boot and this mean to create a shortcut into the startup folder. The batch I need to autostart is:

Code: Select all

del *log.txt
wscript.exe "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Subnet\invisible.vbs" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Subnet\start.bat"
wscript.exe "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Subnet\invisible.vbs" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Subnet\networkmonitor.bat"
wscript.exe "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Subnet\invisible.vbs" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Subnet\fpsmonitor.bat"
This batch file start 3 more batch files

If I go into the batch folder, right click on the file, select make a shortcut and copy and paste in the startup folder it works as intended.
The problem is that I have to create a link, copy it from the directory and paste it into the autostart folder.

I want to make it fully automatic, that means to auto create the shortcut during the installation process.

I tried with this one (https://superuser.com/questions/455364/ ... tch-script ) but every shortcut I create simply doesn't work. The 3 programs are not started by the batch created shortcut.

What can I do?
Maybe I should create a batch file (into the startup folder) that start the batch in the target folder?
Any suggestions is much appreciated

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Create a shortcut via batch file

#2 Post by aGerman » 25 Jan 2018 15:25

How did you customize the script for the shortcut creation?
LiveITA wrote:
25 Jan 2018 14:44
every shortcut I create simply doesn't work
The properties of the shortcut should tell you why it doesn't work.

Steffen

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: Create a shortcut via batch file

#3 Post by Hackoo » 10 Feb 2018 12:04

Just take a look at this https://stackoverflow.com/questions/300 ... in-windows
I just modify a little to create a shortcut on the startup folder instead on the desktop like in the example above

Code: Select all

@echo off
Title Shortcut Creator for your batch and applications files
mode 87,5 & color 9B
Set "ThisBatchFile=%~f0"
Set "ShortcutName=%~n0"
(
	echo Call Shortcut("%ThisBatchFile%","%ShortcutName%"^)
	echo Sub Shortcut(ApplicationPath,ShortcutName^)
	echo    Dim objShell,StartupPath,objShortCut,MyTab
	echo    Set objShell = CreateObject("WScript.Shell"^)
	echo    MyTab = Split(ApplicationPath,"\"^)
	echo    If ShortcutName = "" Then
	echo    ShortcutName = MyTab(UBound(MyTab^)^)
	echo    End if
	echo    StartupPath = objShell.SpecialFolders("Startup"^)
	echo    Set objShortCut = objShell.CreateShortcut(StartupPath ^& "\" ^& ShortcutName ^& ".lnk"^)
	echo    objShortCut.TargetPath = Dblquote(ApplicationPath^)
	echo    ObjShortCut.IconLocation = "%SystemRoot%\system32\shell32.dll,89"
	echo    objShortCut.Save
	echo End Sub
	echo Function DblQuote(Str^)
	echo    DblQuote = Chr(34^) ^& Str ^& Chr(34^)
	echo End Function
)> "%tmp%\Shortcutme.vbs" 
::********************************************************************************************
Start "" /Wait "%tmp%\Shortcutme.vbs"
Del "%tmp%\Shortcutme.vbs"
::***************************************Main Batch*******************************************
cls
echo Done and your main batch goes here !
echo i am a test 
Pause > Nul
::********************************************************************************************

Post Reply