import subprocess
import winreg
import shutil
import os
import webbrowser
import ctypes
import platform
import random

# No longer needed
# option2 = 1
# option4 = 5
# option6 = 10
# option8 = 20

print("Choose an option from the following only one option can be used per run:")
print("/registrychecker       checks for any registry issues on the device")
print("/mainfolder            to open the programdata folder")
print("/specshell             to open the specs of your machine")
print("/deltree               this command is used to delete entire directories only use if you know what you are doingt")
print("/opennotepad           opens notepad")
print("/openbrowser           opens your default browser")
print("/shutdownpc            shuts down your pc")
print("/restartpc             restarts your pc")
print("/opensettings          opens settings")
print("/opensysteminfo        opens system information")

choice = input("Enter your choice: ").strip().lower()  # Get input as a string and convert to lowercase

if choice == "/registrychecker":
    print("Opening registries...")
    subprocess.Popen("regedit.exe")
    print("Windows Registry Editor opened successfully.")
elif choice == "/mainfolder":
    print("Opening programdata.....")
    path = r"C:\ProgramData"  # Use raw string or double backslash
    subprocess.run(['explorer', path])
elif choice == "/specshell":
    print("Generating specifications...")
    
    def get_system_info():
        info = {
            "System": platform.system(),
            "Node Name": platform.node(),
            "Release": platform.release(),
            "Version": platform.version(),
            "Machine": platform.machine(),
            "Processor": platform.processor(),
        }
        return info

    specs = get_system_info()
    for key, value in specs.items():
        print(f"{key}: {value}")
    random_number = random.randint(1, 20) # Changed to use a range.
    print(f"The random number is: {random_number}")
elif choice == "/deltree":
    directory = input("Enter the directory to delete: ")
    
    def deltree(directory):
        """Delete an entire directory tree."""
        if os.path.exists(directory):
            shutil.rmtree(directory)
            print(f"Successfully deleted the directory: {directory}")
        else:
            print(f"The directory {directory} does not exist.")
    
    deltree(directory)
elif choice == "/opennotepad":
    print("Opening Notepad...")
    subprocess.Popen("notepad.exe")
elif choice == "/openbrowser":
    print("Opening your default browser...")
    webbrowser.open_new_tab("google.com")  # Opens a new tab in your default browser
elif choice == "/shutdownpc":
    print("Shutting down your PC...")
    os.system("shutdown /s /t 1")  # Shutdown command
elif choice == "/restartpc":
    print("Restarting your PC...")
    os.system("shutdown /r /t 1")  # Restart command
elif choice == "/opensettings":
    print("Opening Settings...")
    subprocess.Popen("explorer ms-settings:")  # Open Windows Settings
elif choice == "/opensysteminfo":
    print("Opening System Information...")
    subprocess.Popen("msinfo32.exe")  # Open System Information
elif choice == "taskill":  # Corrected: Use "taskill" (consistent with the prompt)
    process_name = input("Enter the name of the process to end (e.g., python.exe): ")
    try:
        subprocess.run(f'taskkill /f /im "{process_name}"', shell=True, check=True)  # Added check=True, and quotes around process_name
        print(f"Successfully ended the application: {process_name}")
    except Exception as e:  # Corrected: Use "Exception" (capitalized)
        print(f"Failed to end the process: {e}")
else:
    print(":( There has been an error. Please try closing and reopening the script and retype the command properly if there is a unidentified error report it to our forms to us at www.scriptcobra.com and give us a breif discription of your error and give us the error code unknown error.")
input("Press Enter to exit...")
