Error running installer for D:\\New Installer\\ChromeSetup.exe: Command '\['D:\\New Installer\\ChromeSetup.exe', '/silent /install'\]' returned non-zero exit status 2147942487.
I try to work on automate installing apps from my pendrive to multiple of laptop. I can install other apps except chrome and firefox. But firefox does not show an error only chrome that show error
"Google Chrome": {
"source": PENDRIVE_PATH,
"installer": "ChromeSetup.exe",
"silent_flag": "/quiet",
"is_zip": False
}
im try to change the silent flag but i guess it does not work.
Here are my code:
import os
import shutil
import subprocess
import zipfile
# Define the pendrive's main folder path
PENDRIVE_PATH = r"D:\New Installer"
# Target path on the laptop where apps will be installed
TARGET_PATH = os.path.join(os.environ["PROGRAMFILES"], "PortableApps")
# List of apps with their setup executables and optional silent flags
apps = {
"7-Zip": {
"source": PENDRIVE_PATH,
"installer": "7z2201-x64.exe",
"silent_flag": "/S",
"is_zip": False
},
"Adobe Reader": {
"source": PENDRIVE_PATH,
"installer": "AcroRdrDC1901220036_en_US.exe",
"silent_flag": "/sAll",
"is_zip": False
},
"Google Chrome": {
"source": PENDRIVE_PATH,
"installer": "ChromeSetup.exe",
"silent_flag": "/quiet",
"is_zip": False
},
"End User Software": {
"source": PENDRIVE_PATH,
"installer": "End_user.msi",
"silent_flag": "/quiet",
"is_zip": False
},
"Mozilla Firefox": {
"source": PENDRIVE_PATH,
"installer": "Firefox Installer.exe",
"silent_flag": "/S",
"is_zip": False
},
"Java Runtime Environment": {
"source": PENDRIVE_PATH,
"installer": "JavaSetup8u351.exe",
"silent_flag": "/s",
"is_zip": False
},
"VLC Media Player": {
"source": PENDRIVE_PATH,
"installer": "vlc-3.0.18-win64.exe",
"silent_flag": "/S",
"is_zip": False
}
}
# Function to copy files from pendrive to laptop
def copy_app_files(app_name, source_path, dest_path):
if not os.path.exists(dest_path):
os.makedirs(dest_path)
shutil.copytree(source_path, dest_path, dirs_exist_ok=True)
print(f"Copied {app_name} files to {dest_path}")
# Function to run the installer if needed
def run_installer(installer_path, silent_flag=None):
try:
# Check if the file is an .msi installer
if installer_path.endswith(".msi"):
command = ["msiexec", "/i", installer_path]
if silent_flag:
command.append(silent_flag)
else:
command = [installer_path]
if silent_flag:
command.append(silent_flag)
subprocess.run(command, check=True)
print(f"Ran installer for {installer_path}")
except Exception as e:
print(f"Error running installer for {installer_path}: {e}")
# Function to extract zip files if needed
def extract_zip(zip_path, extract_to):
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(extract_to)
print(f"Extracted {zip_path} to {extract_to}")
# Main function to install apps
def install_apps():
if not os.path.exists(TARGET_PATH):
os.makedirs(TARGET_PATH)
print(f"Created target directory at {TARGET_PATH}")
for app_name, app_info in apps.items():
source = app_info["source"]
dest = os.path.join(TARGET_PATH, app_name)
installer = os.path.join(source, app_info["installer"])
# Debug: Print the paths being checked
print(f"Looking for {app_name} at {source}")
# Copy the app files to the laptop
if os.path.exists(source):
copy_app_files(app_name, source, dest)
else:
print(f"Source path for {app_name} not found: {source}")
continue
# Check if the app is a zip file
if app_info.get("is_zip"):
if os.path.exists(installer):
extract_zip(installer, dest)
else:
print(f"Zip file not found for {app_name} at {installer}")
else:
# Run the installer if it's an executable
if os.path.exists(installer):
run_installer(installer, app_info.get("silent_flag"))
else:
print(f"Installer not found for {app_name} at {installer}")
print("All applications installed successfully.")
# Run the main function when the script is executed directly
if __name__ == "__main__":
install_apps()