#1 21 May 2019 04:53

PainlessMan
Member
Registered: 20 May 2019
Posts: 1

.msu and .cab installer

Hey there! I'd like to share a code that I was working on, it's just install .msu or .cab files, but u need to rename all them to numbers like 1, 2, 3, 4, 5, 6, 7, 8.. anyway
I'm beginner at batch code so I'd like to get advice if possible smile
Regards

@echo off
:varSection
::i var used to install files
::count1 will be used on :checkingExtension
::count2 will be used on :checkingInfoMsu2 and :checkingInfoCab2
:varSection
set /A i=1
set /A count1=1
set /A count2=1
:checkingExtension
::code below to check if user needs to install msu or cab files, also will check if user sent anything that is not msu or cab as extension file
Color A
echo "+==================================================================+
echo "|                      Checking Extension...                       |
echo "|                  Supported extensions: .msu .cab                 |
echo "+==================================================================+
echo. 
set /p fileType="#%count1% Type the file extension that you want to install - (msu/cab) only: ."
echo.
echo.
echo "+==================================================================+
echo "                      Extension selected: .%fileType%
echo "+==================================================================+
echo.
if /I [%fileType%] == [msu] (
cls
goto checkingInfoMsu1
)
if /I [%fileType%] == [cab] (
cls
goto checkingInfoCab1
)
if /I NOT [%fileType%] == [msu] (
goto msgBox1
)
:msgBox1
::to show message box if user sent anything that is not msu (cab isn't included)
Color C
echo set WshShell = WScript.CreateObject("WScript.shell") > %tmp%\tmp.vbs
echo WScript.Quit (WshShell.Popup(".%fileType% is not a supported extension.",10,"Supported Exntensions: .msu .cab",0)) >> %tmp%\tmp.vbs
cscript /nologo %tmp%\tmp.vbs
del %tmp%\tmp.vbs
cls
set /A count1+=1
goto checkingExtension
:checkingInfoMsu1
::var statatement
Color B
set /p files="Type how many .msu files you have in the folder: " 
set /p folderPath="Copy n paste the full path that your folder is located "
::code below to check if both files quantity and folder path are correct
:checkingInfoMsu2
::checking info sent by user
Color B
cls
echo "+==================================================================+
echo "|#%count2% Number of .msu Files: %files%
echo "|#%count2% Folder Path: %folderPath%\*.msu
echo "+==================================================================+
set /p checkingInfo="Is the amount of .msu files and the folder path correct? (Y/N) only: "
if /I [%checkingInfo%] == [y] (
cls
goto ifSectionMsu
)
if /I [%checkingInfo%] == [yes] (
cls
goto ifSectionMsu
)
if /I [%checkingInfo%] == [n] (
cls
set /A count2+=1
goto checkingInfoMsu1 
)
if /I [%checkingInfo%] == [no] (
cls
set /A count2+=1
goto checkingInfoMsu1 
)
if /I NOT [%checkingInfo%] == [y] (
goto msgBox2 
)
:msgBox2
::to show message box if user sent anything that is not y/yes or n/no
Color C
echo set WshShell = WScript.CreateObject("WScript.shell") > %tmp%\tmp.vbs
echo WScript.Quit (WshShell.Popup("Please type (Y/N)  (%checkingInfo%) is not a valid one",10,"Y or N",0)) >> %tmp%\tmp.vbs
cscript /nologo %tmp%\tmp.vbs
del %tmp%\tmp.vbs
cls
set /A count2+=1
goto checkingInfoMsu2
:ifSectionMsu
::%i% less than or equal %files% goto intallationMsu.. %i% greater than %files% goto doneMsu
if %i% LEQ %files% (
	goto installationMsu
)
if %i% GTR %files% ( 
	goto doneMsu	
)
:installationMsu
::wusa.exe to install msu files
::code below to install all .msu files that user has in his folder
Color F
wusa.exe %folderPath%\%i%.msu /quiet /norestart
echo "+==================================================================+
echo "|                 %i%.msu has been installed...
echo "+==================================================================+
echo.
echo.
::var being incremented
set /A i+=1
goto ifSectionMsu
:doneMsu
::All files have been installed at this time
pause
echo "+==================================================================+
echo "|                                                                  |
echo "|              All .msu files have been installed...               |
echo "|                                                                  |
echo "+==================================================================+
:msgBox3
::will show message box then exit
echo set WshShell = WScript.CreateObject("WScript.shell") > %tmp%\tmp.vbs
echo WScript.Quit (WshShell.Popup("All files have been installed",10,"All done!")) >> %tmp%\tmp.vbs
cscript /nologo %tmp%\tmp.vbs
if %errorlevel% == 1 (
del %tmp%\tmp.vbs
exit
)else (
del %tmp%\tmp.vbs
exit
)
del %tmp%\tmp.vbs
cls
exit
:checkingInfoCab1
::var statatement
Color B
set /p files="Type how many .cab files you have in the folder: " 
set /p folderPath="Copy n paste the full path that your folder is located "
:checkingInfoCab2
::checking info sent by user
Color B
cls
echo "+==================================================================+
echo "|#%count2% Number of .cab Files: %files%
echo "|#%count2% Folder Path: %folderPath%\*.cab
echo "+==================================================================+
set /p checkingInfo="Is the amount of .cab files and the folder path correct? (Y/N) only: "
if /I [%checkingInfo%] == [y] ( 
cls
goto ifSectionCab
)
if /I [%checkingInfo%] == [yes] ( 
cls
goto ifSectionCab
)
if /I [%checkingInfo%] == [n] (
cls
set /A count2+=1
goto checkingInfoCab1 
)
if /I [%checkingInfo%] == [no] (
cls
set /A count2+=1
goto checkingInfoCab1 
)
if /I NOT [%checkingInfo%] == [y] (
goto msgBox4 
)
:msgBox4
::to show message box if user sent anything that is not y/yes or n/no
Color C
echo set WshShell = WScript.CreateObject("WScript.shell") > %tmp%\tmp.vbs
echo WScript.Quit (WshShell.Popup("Please type Y or N. (%checkingInfo%) is not a valid one",10,"Y or N",0)) >> %tmp%\tmp.vbs
cscript /nologo %tmp%\tmp.vbs
del %tmp%\tmp.vbs
cls
set /A count2+=1
goto checkingInfoCab2
:ifSectionCab
::%i% less than or equal %files% goto intallationMsu.. %i% greater than %files% goto doneMsu
if %i% LEQ %files% (
	goto installationCab
)
if %i% GTR %files% ( 
	goto doneCab	
)
:installationCab
::pkgmgr /ip to install .cab files
::code below to install all .cab files that user has in his folder
Color F
pkgmgr /ip /m:%folderPath%\%i%.cab /quiet /norestart
echo "+==================================================================+
echo "|                 %i%.cab has been installed...
echo "+==================================================================+
echo.
echo.
set /A i+=1
goto ifSectionCab
:doneCab
::All files have been installed at this time
echo "+==================================================================+
echo "|                                                                  |
echo "|              All .cab files have been installed...               |
echo "|                                                                  |
echo "+==================================================================+
:msgBox5
::will show message box then exit
echo set WshShell = WScript.CreateObject("WScript.shell") > %tmp%\tmp.vbs
echo WScript.Quit (WshShell.Popup("All files have been installed",5,"All done!",0)) >> %tmp%\tmp.vbs
cscript /nologo %tmp%\tmp.vbs
if %errorlevel% == 1 (
del %tmp%\tmp.vbs
exit
)else (
del %tmp%\tmp.vbs
exit
)
del %tmp%\tmp.vbs
cls
exit

Offline

Board footer

Powered by FluxBB