Can and how you set a custom errorlevel?

0

I want to create a file to install a program, LanSchool, and have error codes to help me troubleshoot because it will probably have a few bugs. Anyone have an idea? I've tried several differently phrased Google searches, none gave me anything. I appreciate all the help I can get!

@ECHO off
echo Made by anonymous. All rights reserved.
echo I am not responible for any issues caused by this script.
echo/
echo Warning: This script is expiremental. Use at your own risk.
pause
cls
echo Would you like to install or delete LanSchool? (I/D)
echo I = Install, D = Delete
set/p "cho=>"
if %cho%==I goto Install
if %cho%==i goto Install
if %cho%==D goto Delete
if %cho%==d goto Delete
echo Invalid choice.
:Delete
echo Are you sure you want to delete LanSchool? (Y/N)
set/p "cho=>"
if %cho%==Y del C:\Program Files (x86)\LanSchool\
if %cho%==y del C:\Program Files (x86)\LanSchool\
if %cho%==N goto errorcodes
if %cho%==n goto errorcodes 
echo Invalid choice.
IF EXIST "C:\Program Files (x86)\LanSchool\" goto failundeleted
echo Success!
pause
cls
:install
cls
if not exist C:\PROGRA~2\LANSCH~1\ set errorlevel=10
if not exist C:\PROGRA~2\LANSCH~1\ goto errorcodes
echo Would you like to install student, teacher, or no LanSchool?
echo S = Student, T = Teacher, N = None.
set/p "cho=>"
if %cho%==T goto installteacher
if %cho%==t goto installteacher
if %cho%==S goto installstudent
if %cho%==s goto installstudent
if %cho%==N goto errorcodes
if %cho%==n goto errorcodes
echo Invalid choice.
:installstudent
Msiexec.exe /i "student.msi" /qn ADVANCED_OPTIONS=1 AD_SECURE_MODE=1
goto end
:installteacher
Msiexec.exe /i "teacher.msi" /qn ADVANCED_OPTIONS=1 AD_SECURE_MODE=1
goto end
:failundeleted
echo Program failed, sorry. Please talk to whoever gave you this program. 
echo Error Code: LANSCHOOL_FILES_NOT_DELETED
pause
goto end
:errorcodes
IF ERRORLEVEL 0 goto end
if errorlevel 1 echo Error Code: INCORRECT_FUNCTION
if errorlevel 2 echo Error Code: FILE_NOT_FOUND
if errorlevel 3 echo Error Code: PATH_NOT_FOUND
if errorlevel 5 echo Error Code: PERMISSIONS_DENIED
if errorlevel 3221225477 echo ERROR Code: PROGRAM_ABNORMALLY_CRASHED
if errorlevel 0xC0000005 echo ERROR Code: PROGRAM_ABNORMALLY_CRASHED
if errorlevel -1073741819 echo ERROR Code: PROGRAM_ABNORMALLY_CRASHED
if errorlevel 10 echo Error Code: LANSCHOOL_ALREADY_INSTALLED
pause
:end
pause
batch-file
asked on Stack Overflow Nov 8, 2019 by Grayson Tinker • edited Nov 8, 2019 by Grayson Tinker

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0