I´m building a small batch script which moves some files and creates three startmenu entries. The problem is about the lines 30 to 32 where I call the method "createLink". In these lines I call a function which creates the entries for the startmenu. But only the first one is created. It does not matter which one of these three is first called. Only the first entry called is created. Here is the hole script:
@echo off
chcp 1252
set ProgramFilesPath=%ProgramFiles%\Grün2_Mitgliederverwaltung\
set AppDataPath=%AppData%\Grün2_Mitgliederverwaltung\
set MenuEntryFolderPath=%AppData%\Microsoft\Windows\Start Menu\Programs\Grün2 Mitgliederverwaltung\
if not exist "%AppDataPath%" (
mkdir "%AppDataPath%"
)
move /y "%~dp0Grün2.VisualElementsManifest.xml" "%AppDataPath%"
del "%~dp0*.sh"
del "%~dp0*.desktop"
if not exist "%ProgramFilesPath%" (
move /y "%~dp0Grün2.conf" "%AppDataPath%"
call :getAdminrights
rem "install"
mkdir "%ProgramFilesPath%"
move /y "%~dp0*" "%ProgramFilesPath%"
rem moving directories between drives is not possible
xcopy /y "%~dp0lib" "%ProgramFilesPath%lib\"
rd /s /q "%~dp0lib"
rem create startmenuentries
mkdir "%MenuEntryFolderPath%"
call :createLink "Grün2 starten" "%ProgramFilesPath%" "Grün2_Launcher.jar"
call :createLink "Grün2 deinstallieren" "%ProgramFilesPath%" "uninstall.bat"
call :createLink "Grün2 konfigurieren" "%AppDataPath%" "Grün2.conf"
echo.
echo Programm wurde installiert
) else (
del "%~dp0Grün2.conf"
call :getAdminrights
rem "update"
move /y "%~dp0*" "%ProgramFilesPath%"
rem moving directories between drives is not possible
xcopy /y "%~dp0lib" "%ProgramFilesPath%lib\"
rd /s /q "%~dp0lib"
echo.
echo Programm wurde aktualisiert
)
goto :eof
rem createLink <linkname> <workingdir> <file of workingdir>
:createLink
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%MenuEntryFolderPath%%~1.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "%~2%~3" >> %SCRIPT%
echo oLink.WorkingDirectory = "%~2" >> %SCRIPT%
echo oLink.IconLocation = "%ProgramFilesPath%icon.ico" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%
goto :eof
:getAdminrights
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\icacls.exe" "%SYSTEMROOT%\system32\config\system"
set ADMINSCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
REM --> If error flag set, we do not have admin.
if '%ERRORLEVEL%' NEQ '0' (
echo Set UAC = CreateObject^("Shell.Application"^) > %ADMINSCRIPT%
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> %ADMINSCRIPT%
cscript /nologo %ADMINSCRIPT%
del %ADMINSCRIPT%
)
goto :eof
I also recognized that only the first call of :createLink
produces a vbs file in %Temp%. At least it contains the correct code:
Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = "C:\Users\Username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Grün2 Mitgliederverwaltung\Grün2 starten.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
oLink.TargetPath = "C:\Program Files\Grün2_Mitgliederverwaltung\Grün2_Launcher.jar"
oLink.WorkingDirectory = "C:\Program Files\Grün2_Mitgliederverwaltung\"
oLink.IconLocation = "C:\Program Files\Grün2_Mitgliederverwaltung\icon.ico"
oLink.Save