This script is responsible for uninstalling the Maestro software versions (Maestro BPM, Maestro ERP, Maestro MCA, Maestro Nest) present on the system. It searches for directories where Maestro products may be installed, deletes the found files and folders, and logs the removal in a log file.
- Search for Maestro installation directories: The script checks standard directories where Maestro products might be installed.
- File deletion: The script iterates through the found directories and deletes all files and subfolders within them.
- Removal logging: If the file removal is successful, the message "Maestro successfully removed" is recorded in the log file.
- Logs: The log file is stored at
C:\Windows\Temp\Maestro_Uninstall_Log.txt.
import os
import shutil
import timeThese libraries are used for file and directory operations:
os: For checking the existence of directories and file handling.shutil: For removing files and folders.time: For recording the date and time of the removal in the log.
maestro_paths = [
r"C:\Program Files\Maestro BPM",
r"C:\Program Files (x86)\Maestro BPM",
r"C:\Users\Public\Maestro BPM",
r"C:\Program Files\Maestro ERP",
r"C:\Program Files (x86)\Maestro ERP",
r"C:\Users\Public\Maestro ERP",
r"C:\Program Files\Maestro MCA",
r"C:\Program Files (x86)\Maestro MCA",
r"C:\Users\Public\Maestro MCA",
r"C:\Program Files\Maestro Nest",
r"C:\Program Files (x86)\Maestro Nest",
r"C:\Users\Public\Maestro Nest"
]These are the directories the script will check for installed Maestro products. The list covers several possible locations, including both 32-bit and 64-bit systems, as well as public folders.
log_path = r"C:\Windows\Temp\Maestro_Uninstall_Log.txt"This is the path to the log file where the removal of Maestro will be recorded, if successful.
def log_remocao():
"""Logs only the message 'Maestro successfully removed' in the log file"""
try:
with open(log_path, "a") as log_file:
log_file.write(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - Maestro successfully removed\n")
print("Maestro successfully removed") # Displays in the terminal
except Exception:
pass # Ignores errors when writing to the logThis function is responsible for recording in the log file that Maestro was successfully removed, including the date and time of the removal. If an error occurs while writing to the log, it is silently ignored.
def excluir_arquivos(directory):
"""Deletes all files and folders within the provided directory"""
removed = False
for root, dirs, files in os.walk(directory, topdown=False):
for name in files:
try:
os.remove(os.path.join(root, name))
removed = True
except Exception:
pass
for name in dirs:
try:
shutil.rmtree(os.path.join(root, name))
removed = True
except Exception:
pass
return removedThis function walks through the given directory and deletes all files and folders inside. It returns True if any file or folder was successfully removed, otherwise False.
def desinstalar_maestro():
"""Uninstalls all detected versions of Maestro"""
something_removed = False
for path in maestro_paths:
if os.path.exists(path):
if excluir_arquivos(path):
something_removed = True
if something_removed:
log_remocao()
else:
print("No Maestro version found.") # No log is createdThis function checks if any of the default directories contain installed Maestro products. If found, it calls the excluir_arquivos() function to delete the files. If at least one directory is removed, the log_remocao() function is called to log the removal. If no Maestro products are found, a message is displayed in the terminal.
if __name__ == "__main__":
desinstalar_maestro()This line ensures that the script will only run when executed directly (not when imported as a module). It calls the desinstalar_maestro() function to start the uninstallation process.
- Run the script: Simply execute the script in a Python environment. It will attempt to locate and remove Maestro installations and log the removal.
- Check the log: After execution, the log file at
C:\Windows\Temp\Maestro_Uninstall_Log.txtcan be checked to confirm the removals performed.
- More robust error handling: In case of failure during file deletion or log writing, the script could log more detailed error information.
- Additional checks: The script could be modified to search other locations or perform permission checks before attempting deletion.
This script was designed to streamline the removal of Maestro versions and ensure the process is recorded in a simple and effective way.