To check whether a batch file/script has been successfully executed, a condition check is generally included as the last command in the script. This condition checks the status of execution, and depending on whether or not the script was executed successfully, returns a value. A successful script execution returns a 0 while an unsuccessful one returns a non-zero value that is interpreted as an Error Code or an errorlevel.
Use the command EXIT /B %ERRORLEVEL% at the end of the batch file to return the error codes from the batch file
Note: Environment variables are a set of dynamic named values that can affect the way, running processes will behave on a computer. For example, an environment variable with a standard name can store the location that a particular computer system uses to store user profile this may vary from one computer system to another.
In the batch file , it is always a good practice to use environment variables instead of constant values. Since the same variable get expanded to different values on different computers.
Example:
Batch file for Copying File to a Folder
md "C:manageengine"
copy "\\sharename\foldername\samplefile.txt" "C:\manageengine"
exit /b %ERRORLEVEL%