❓ Help Batch Scripting

Status
Not open for further replies.

whisker

Eternal Poster
How to 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"
 
There are several improvements that you can make to this batch script. Here are some suggestions:

1. Use quotes around the file paths and arguments to handle spaces in the file path or argument names.

2. Use a variable for the Office version and configuration file name to make the script more readable and easier to modify.

3. Add error handling to detect and handle any errors that may occur during the installation process.

Here's an improved version of the script that incorporates these suggestions:

Code:
@echo off

set "OFFICE_VERSION=Office2021"
set "CONFIG_FILE=%~dp0Office\%OFFICE_VERSION%(Excel,PowerPoint,Publisher,Word)_Configuration.xml"

if not exist "%CONFIG_FILE%" (
  echo Configuration file not found: "%CONFIG_FILE%"
  exit /b 1
)

call "%~dp0Office\setup.exe" /download "%CONFIG_FILE%"

if %errorlevel% neq 0 (
  echo Installation failed with error code %errorlevel%.
  exit /b %errorlevel%
)

echo Installation successful.

This version of the script uses the set command to define variables for the Office version and configuration file name. The if not exist command is used to check if the configuration file exists before running the installation. The call command is used to run the setup.exe file with the specified configuration file. Finally, the if statement is used to check the errorlevel after the installation completes and print an appropriate message based on the error code.
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 330
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,129
Guests online
948
Total visitors
2,077

Forum statistics

Threads
2,273,741
Posts
28,951,230
Members
1,234,939
Latest member
bloody666
Back
Top