Advertisement
Najeebsk

N-CMDER.pyw

Apr 2nd, 2024 (edited)
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.84 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("Najeeb CMDER 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. # Function to search for a query in the output text
  115. def search_query():
  116.     query = search_entry.get()
  117.     if query:
  118.         search_text(output_text, query)
  119.     else:
  120.         messagebox.showwarning("Warning", "Please enter a search query.")
  121.  
  122. # Function to search for a query within a text widget
  123. def search_text(text_widget, query):
  124.     text_widget.tag_remove('highlight', '1.0', tk.END)
  125.     count = tk.IntVar()
  126.     idx = '1.0'
  127.     while True:
  128.         idx = text_widget.search(query, idx, nocase=1, stopindex=tk.END, count=count)
  129.         if not idx:
  130.             break
  131.         line_start = text_widget.index('%s linestart' % idx)
  132.         line_end = text_widget.index('%s lineend' % idx)
  133.         text_widget.tag_add('highlight', line_start, line_end)
  134.         idx = line_end
  135.     text_widget.tag_config('highlight', background='yellow')
  136.  
  137. # Dropdown list of commands
  138. commands = [
  139.     "--[NAJEEB PC TOOLS]--",
  140.     "--[HELP= -H ; --H ; -Help ; --Help ; /? ; ?]--",
  141.     "Everything.exe -search Najeeb",
  142.     "ES.exe -a jpg",
  143.     "WHERE /R D:\ *.mp4",
  144.     "TYPE C:\CMDER\BOOKS\COMMANDS.txt",
  145.     "START C:/CMDER/BOOK.py",
  146.     "START C:\CMDER\TOOLS\LIST.pyw",
  147.     "START C:\CMDER\TOOLS\RENAME-EXT.pyw",
  148.     "START C:\CMDER\TOOLS\ALL-RADIOS.pyw",
  149.     "START C:\CMDER\TOOLS\TOOL.ahk",
  150.     "START C:\CMDER\SOFT\SOFT.ahk",
  151.     "START C:\CMDER\APP\APPS.ahk",
  152.     "START C:\CMDER\HOME.ahk",
  153.     "START C:\CMDER\TOOLS.ahk",
  154.     "START C:\CMDER\COMMANDER.ahk",
  155.     "START C:\CMDER\CMDR.ahk",
  156.     "START C:\CMDER\CMD.ahk",
  157.     "START C:\CMDER\FFMPEG.ahk",
  158.     "START C:\CMDER\AHK.ahk",
  159.     "--[NAJEEB PC INFORMATION]--",
  160.     "systeminfo",
  161.     "msinfo32",
  162.     "compmgmt.msc",
  163.     "diskmgmt.msc",
  164.     "devmgmt.msc",
  165.     "Control Panel",
  166.     "START shell:AppData",
  167.     "START shell:Startup",
  168.     "START shell:ProgramFiles",
  169.     "START C:/Users/Najeeb/AppData/Local/Temp",
  170.     "START C:\Windows\Prefetch",
  171.     "START C:\Windows\Temp",
  172.     "TZUTIL /L",
  173.     "TZUTIL /G",
  174.     'TZUTIL /S "Pakistan Standard Time"',
  175.     "tasklist",
  176.     "whoami",
  177.     "whoami /priv",
  178.     "cmdkey /list",
  179.     'dir "C:\\Program Files"',
  180.     'dir /S /B /A "C:\\"',
  181.     'dir /S /B /A "D:\\"',
  182.     'dir /S /B /A "E:\\"',
  183.     'dir /S /B /A "F:\\"',
  184.     'dir /S /B /A "G:\\"',
  185.     'dir /S /B /A "I:\\"',
  186.     'dir /S /B /A "Z:\\"',
  187.     "--[NIRCMD Commands]--",
  188.     "nircmd.exe emptybin & Exit",
  189.     "nircmd.exe mutesysvolume 1",
  190.     "nircmd.exe mutesysvolume 0",
  191.     'nircmd.exe loop 10 60000 savescreenshot "~$folder.desktop$\P~$loopcount$.png" & Exit',
  192.     "--[CMD HELP COMMANDS]--",
  193.     "Help >> Help.txt",
  194.     "WHERE /?",
  195.     "wget --help",
  196.     "FFMPEG -h",
  197.     "youtube-dl -h",
  198.     "magick -help",
  199.     "wget --help",  
  200.     "DOSKEY /?",
  201.     "netsh /?",
  202.     "wmic /?",
  203. ]
  204.  
  205. # Create dropdown list
  206. command_options = ttk.Combobox(window, values=commands, state="readonly", width=74, font=("Arial", 12))
  207. command_options.grid(row=1, column=0, padx=10, pady=(10, 5))
  208.  
  209. # Entry field for custom command
  210. custom_command_entry = tk.Entry(window, width=74, font=("Arial", 12))
  211. custom_command_entry.grid(row=2, column=0, padx=10, pady=5)
  212.  
  213. # Button to execute selected command
  214. execute_button = tk.Button(window, text="Execute Selected Command", command=execute_selected_command, fg="White", bg="Blue")
  215. execute_button.grid(row=1, column=1, padx=10, pady=(10, 5), sticky="w")
  216.  
  217. # Button to execute custom command
  218. execute_custom_button = tk.Button(window, text="Execute Custom Command", command=execute_custom_command, fg="White", bg="Blue")
  219. execute_custom_button.grid(row=2, column=1, padx=10, pady=5, sticky="w")
  220.  
  221. # Button to clear output
  222. clear_button = tk.Button(window, text="Clear Text Field", command=clear_output, fg="white", bg="Red")
  223. clear_button.grid(row=1, column=2, padx=10, pady=(10, 5), sticky="w")
  224.  
  225. # Button to save result
  226. save_button = tk.Button(window, text="Save Result", command=save_result, fg="white", bg="Green")
  227. save_button.grid(row=1, column=3, padx=10, pady=(10, 5), sticky="w")
  228.  
  229. # Button to show help.txt
  230. help_button = tk.Button(window, text="Show Help", command=show_help, fg="black", bg="yellow")
  231. help_button.grid(row=1, column=4, padx=10, pady=(10, 5), sticky="w")
  232.  
  233. # Button to delete help.txt
  234. delete_help_button = tk.Button(window, text="Delete Help", command=delete_help_file, fg="black", bg="orange")
  235. delete_help_button.grid(row=2, column=4, padx=10, pady=5, sticky="w")
  236.  
  237. # Search entry field
  238. search_entry = tk.Entry(window, width=74, font=("Arial", 12))
  239. search_entry.grid(row=3, column=0, padx=10, pady=5)
  240.  
  241. # Button to perform search
  242. search_button = tk.Button(window, text="Search Command", command=search_query, fg="black", bg="lightblue")
  243. search_button.grid(row=3, column=1, padx=10, pady=5, sticky="w")
  244.  
  245. # Text field to display output
  246. output_text = scrolledtext.ScrolledText(window, width=107, height=27, wrap=tk.WORD, font=("Arial", 12))
  247. output_text.grid(row=4, column=0, columnspan=5, padx=10, pady=10, sticky="nsew")
  248.  
  249. # Label for the heading
  250. heading_label = tk.Label(window, text="NAJEEB ALL PC INFORMATION", font=("Arial", 24, "bold"), bg="#336699", fg="white")
  251. heading_label.grid(row=0, column=0, columnspan=5, pady=(5, 10))
  252.  
  253. # Bind double-click event to output text field
  254. output_text.bind("<Double-Button-1>", on_double_click)
  255.  
  256. # Configure grid weights to make the text field expandable
  257. window.grid_columnconfigure(0, weight=1)
  258. window.grid_rowconfigure(3, weight=1)
  259.  
  260. # Run the Tkinter event loop
  261. window.mainloop()
  262.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement