What's new

Help Batch Scripting

whisker

Eternal Poster
Can you show me if there is something wrong in this script below? Or show me how do I improve it?

Code:
@echo off
title Microsoft Office Deployment Tool Installer Script ver.01
net session >nul 2>&1
if %errorLevel% == 0 (goto :continue) else (
echo.
echo.    [ERROR] This script requires administrator privileges to run.
echo.    [INFO] To do so, right-click on this script and select "Run as administrator"
echo.
pause
goto :eof
)

:continue
echo.
echo.    -----------------------------------
echo.    [WARNING] DO NOT CLOSE THIS WINDOW!
echo.    -----------------------------------
echo.
echo [Office Deployment Tool] Downloading installation files, this may take time...
call "%~dp0Office\setup.exe /download %~dp0Office\Office2021(Excel,PowerPoint,Publisher,Word)_Configuration.xml"
cls
echo.
echo.    -----------------------------------
echo.    [WARNING] DO NOT CLOSE THIS WINDOW!
echo.    -----------------------------------
echo.
echo [Office Deployment Tool] Installing Microsoft Office, this may take time...
call "%~dp0Office\setup.exe /configure %~dp0Office\Office2021(Excel,PowerPoint,Publisher,Word)_Configuration.xml"
cls
echo.
echo.    -----------------------------------
echo.    [WARNING] DO NOT CLOSE THIS WINDOW!
echo.    -----------------------------------
echo.
echo [INFO] Configuring, please wait...
call "%~dp0Ac†ïvâ†ør\AutoRenewal-Setup.cmd"
cls
echo.
echo.    [INFO] Microsoft Office is successfully installed.
echo.    [INFO] You can now close this window by pressing any key on your keyboard or by clicking the close button.
echo.
pause
exit /b
 
The script appears to be functional and well-written overall. However, there are a few suggestions for improvement:

1. Error handling: It is good practice to include error handling in the script. For example, you can add a check to verify that the installation files have been downloaded successfully before proceeding with the installation.

2. Logging: Adding logging statements to the script can help with troubleshooting issues that may occur during the installation process.

3. Input validation: You could add input validation to ensure that the configuration file and other required files exist before attempting to install Office.

4. Use of variables: You could use variables to store the paths of the installation files, making the script easier to read and maintain.

5. Use of quotes: It is best practice to enclose file paths in quotes in case there are spaces or special characters in the path.

6. Consistency: Make sure that the naming conventions for files and directories are consistent and easy to read.

Overall, the script looks good and should work as intended. However, incorporating the above suggestions will make the script more robust and easier to maintain in the long run.
 
How do I improve this? Or Show me the proper way on how to do it.
Code:
call "%~dp0Office\setup.exe /download %~dp0Office\Office2021(Excel,PowerPoint,Publisher,Word)_Configuration.xml"
 
Back
Top