Advertisement
Najeebsk

N2-CMDER.pyw

Apr 3rd, 2024 (edited)
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.64 KB | None | 0 0
  1. import subprocess
  2. import tkinter as tk
  3. from tkinter import ttk
  4. from tkinter import scrolledtext
  5. from tkinter import messagebox
  6. from tkinter import filedialog
  7. import os
  8. import platform
  9.  
  10. # Create a Tkinter window
  11. window = tk.Tk()
  12. window.geometry("1000x680")
  13. window.configure(bg="#336699")
  14. window.title("Windows Information PC Management Tool")
  15.  
  16. # Function to execute shell commands
  17. def run_command(command):
  18.     try:
  19.         if command.startswith(('dir ', 'WHERE ', 'ping ', 'wmic ', 'assoc ', 'break ', 'call ', 'cd ', 'chdir ', 'cls ', 'color ', 'copy ', 'date ', 'del ', 'erase ', 'dir ', 'echo ', 'exit ', 'mkdir ', 'mklink ', 'move ', 'rd ', 'rmdir ', 'ren ', 'rename ', 'rmdir ', 'set ', 'setlocal ', 'shift ', 'start ', 'time ', 'title ', 'ver ', 'vol ', 'netsh ')):
  20.             # Use os.system for commands like dir, WHERE, ping, wmic, and cmd commands
  21.             result = os.popen(command).read()
  22.         elif command.startswith('help'):
  23.             # For 'help' command, execute 'cmd /c help' to get help info
  24.             result = subprocess.run(['cmd', '/c', 'help'], capture_output=True, text=True, check=True).stdout.strip()
  25.         else:
  26.             # Use subprocess.run for other commands
  27.             result = subprocess.run(command, capture_output=True, text=True, shell=True, check=True).stdout.strip()
  28.         return result
  29.     except subprocess.CalledProcessError as e:
  30.         messagebox.showerror("Error", f"Command failed: {e.stderr}")
  31.     except FileNotFoundError:
  32.         messagebox.showerror("Error", "Executable file not found. Please check your command.")
  33.     return None
  34.  
  35. # Function to display selected command result
  36. def execute_selected_command():
  37.     selected_command = command_options.get()
  38.     if selected_command:
  39.         output_text.delete(1.0, tk.END)  # Clear previous output
  40.         result = run_command(selected_command)
  41.         if result:
  42.             output_text.insert(tk.END, result)
  43.         else:
  44.             output_text.insert(tk.END, "No data available.")
  45.  
  46. # Function to execute custom command
  47. def execute_custom_command():
  48.     custom_command = custom_command_entry.get()
  49.     if custom_command:
  50.         output_text.delete(1.0, tk.END)  # Clear previous output
  51.         result = run_command(custom_command)
  52.         if result:
  53.             output_text.insert(tk.END, result)
  54.         else:
  55.             output_text.insert(tk.END, "No data available.")
  56.     else:
  57.         messagebox.showwarning("Warning", "Please enter a command.")
  58.  
  59. # Function to clear the output text field
  60. def clear_output():
  61.     output_text.delete(1.0, tk.END)
  62.  
  63. # Function to save displayed result to a text file
  64. def save_result():
  65.     result = output_text.get(1.0, tk.END)
  66.     if result.strip():
  67.         file_path = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files", "*.txt")])
  68.         if file_path:
  69.             with open(file_path, "w") as file:
  70.                 file.write(result)
  71.                 messagebox.showinfo("Success", "Result saved successfully.")
  72.     else:
  73.         messagebox.showwarning("Warning", "No data to save.")
  74.  
  75. # Function to show help.txt
  76. def show_help():
  77.     # Save help information to Help.txt file
  78.     #run_command('Help >> Help.txt')
  79.     # Read help information from file
  80.     with open("Help.txt", "r") as file:
  81.         help_text = file.read()
  82.     if help_text:
  83.         output_text.delete(1.0, tk.END)
  84.         output_text.insert(tk.END, help_text)
  85.     else:
  86.         output_text.delete(1.0, tk.END)
  87.         output_text.insert(tk.END, "No help available.")
  88.  
  89. # Function to delete help.txt
  90. def delete_help_file():
  91.     try:
  92.         os.remove("Help.txt")
  93.         messagebox.showinfo("Success", "Help.txt deleted successfully.")
  94.     except FileNotFoundError:
  95.         messagebox.showwarning("Warning", "Help.txt not found.")
  96.  
  97. # Function to open file with default program
  98. def open_with_default_program(file_path):
  99.     if platform.system() == "Windows":
  100.         os.startfile(file_path)
  101.     elif platform.system() == "Darwin":
  102.         subprocess.call(["open", file_path])
  103.     else:
  104.         subprocess.call(["xdg-open", file_path])
  105.  
  106. # Function to handle double-click event on output text
  107. def on_double_click(event):
  108.     index = output_text.index("@%s,%s" % (event.x, event.y))
  109.     line, column = map(int, index.split('.'))
  110.     word = output_text.get('%d.0' % line, '%d.end' % line)
  111.     if os.path.isfile(word.strip()):
  112.         open_with_default_program(word.strip())
  113.  
  114. # Dropdown list of commands
  115. commands = [
  116.     "--[NAJEEB PC TOOLS]--",
  117.     "--[HELP= -H ; --H ; -Help ; --Help ; /? ; ?]--",
  118.     "Everything.exe -search Najeeb",
  119.     "ES.exe -a jpg",
  120.     "WHERE /R D:\ *.mp4",
  121.     "TYPE C:\CMDER\BOOKS\COMMANDS.txt",
  122.     "START C:/CMDER/BOOK.py",
  123.     "START C:\CMDER\TOOLS\LIST.pyw",
  124.     "START C:\CMDER\TOOLS\RENAME-EXT.pyw",
  125.     "START C:\CMDER\TOOLS\ALL-RADIOS.pyw",
  126.     "START C:\CMDER\TOOLS\TOOL.ahk",
  127.     "START C:\CMDER\SOFT\SOFT.ahk",
  128.     "START C:\CMDER\APP\APPS.ahk",
  129.     "START C:\CMDER\HOME.ahk",
  130.     "START C:\CMDER\TOOLS.ahk",
  131.     "START C:\CMDER\COMMANDER.ahk",
  132.     "START C:\CMDER\CMDR.ahk",
  133.     "START C:\CMDER\CMD.ahk",
  134.     "START C:\CMDER\FFMPEG.ahk",
  135.     "START C:\CMDER\AHK.ahk",
  136.     "--[NAJEEB PC INFORMATION]--",
  137.     "systeminfo",
  138.     "msinfo32",
  139.     "compmgmt.msc",
  140.     "diskmgmt.msc",
  141.     "devmgmt.msc",
  142.     "Control Panel",
  143.     "START shell:AppData",
  144.     "START shell:Startup",
  145.     "START shell:ProgramFiles",
  146.     "START C:/Users/Najeeb/AppData/Local/Temp",
  147.     "START C:\Windows\Prefetch",
  148.     "START C:\Windows\Temp",
  149.     "TZUTIL /L",
  150.     "TZUTIL /G",
  151.     'TZUTIL /S "Pakistan Standard Time"',
  152.     "tasklist",
  153.     "whoami",
  154.     "whoami /priv",
  155.     "cmdkey /list",
  156.     'dir "C:\\Program Files"',
  157.     'dir /S /B /A "C:\\"',
  158.     'dir /S /B /A "D:\\"',
  159.     'dir /S /B /A "E:\\"',
  160.     'dir /S /B /A "F:\\"',
  161.     'dir /S /B /A "G:\\"',
  162.     'dir /S /B /A "I:\\"',
  163.     'dir /S /B /A "Z:\\"',
  164.     "--[NIRCMD Commands]--",
  165.     "nircmd.exe emptybin & Exit",
  166.     "nircmd.exe mutesysvolume 1",
  167.     "nircmd.exe mutesysvolume 0",
  168.     'nircmd.exe loop 10 60000 savescreenshot "~$folder.desktop$\P~$loopcount$.png" & Exit',
  169.     "--[CMD HELP COMMANDS]--",
  170.     "Help >> Help.txt",
  171.     "WHERE /?",
  172.     "wget --help",
  173.     "FFMPEG -h",
  174.     "youtube-dl -h",
  175.     "magick -help",
  176.     "wget --help",  
  177.     "DOSKEY /?",
  178.     "netsh /?",
  179.     "wmic /?",
  180. ]
  181.  
  182. # Create dropdown list
  183. command_options = ttk.Combobox(window, values=commands, state="readonly", width=74, font=("Arial", 12))
  184. command_options.grid(row=1, column=0, padx=10, pady=(10, 5))
  185.  
  186. # Entry field for custom command
  187. custom_command_entry = tk.Entry(window, width=74, font=("Arial", 12))
  188. custom_command_entry.grid(row=2, column=0, padx=10, pady=5)
  189.  
  190. # Button to execute selected command
  191. execute_button = tk.Button(window, text="Execute Seleted Command", command=execute_selected_command, fg="White", bg="Blue")
  192. execute_button.grid(row=1, column=1, padx=10, pady=(10, 5), sticky="w")
  193.  
  194. # Button to execute custom command
  195. execute_custom_button = tk.Button(window, text="Execute Custom Command", command=execute_custom_command, fg="White", bg="Blue")
  196. execute_custom_button.grid(row=2, column=1, padx=10, pady=5, sticky="w")
  197.  
  198. # Button to clear output
  199. clear_button = tk.Button(window, text="Clear", command=clear_output, fg="white", bg="Red")
  200. clear_button.grid(row=1, column=2, padx=10, pady=(10, 5), sticky="w")
  201.  
  202. # Button to save result
  203. save_button = tk.Button(window, text="Save Result", command=save_result, fg="white", bg="Green")
  204. save_button.grid(row=1, column=3, padx=10, pady=(10, 5), sticky="w")
  205.  
  206. # Button to show help.txt
  207. help_button = tk.Button(window, text="Show Help", command=show_help, fg="black", bg="yellow")
  208. help_button.grid(row=1, column=4, padx=10, pady=(10, 5), sticky="w")
  209.  
  210. # Button to delete help.txt
  211. delete_help_button = tk.Button(window, text="Delete Help", command=delete_help_file, fg="black", bg="orange")
  212. delete_help_button.grid(row=2, column=4, padx=10, pady=5, sticky="w")
  213.  
  214. # Text field to display output
  215. output_text = scrolledtext.ScrolledText(window, width=107, height=28, wrap=tk.WORD, font=("Arial", 12))
  216. output_text.grid(row=3, column=0, columnspan=5, padx=10, pady=10, sticky="nsew")
  217.  
  218. # Label for the heading
  219. heading_label = tk.Label(window, text="NAJEEB ALL PC INFORMATION", font=("Arial", 24, "bold"), bg="#336699", fg="white")
  220. heading_label.grid(row=0, column=0, columnspan=5, pady=(5, 10))
  221.  
  222. # Bind double-click event to output text field
  223. output_text.bind("<Double-Button-1>", on_double_click)
  224.  
  225. # Configure grid weights to make the text field expandable
  226. window.grid_columnconfigure(0, weight=1)
  227. window.grid_rowconfigure(3, weight=1)
  228.  
  229. # Run the Tkinter event loop
  230. window.mainloop()
  231.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement