Savelyev_Vyacheslav

docController

Apr 18th, 2021 (edited)
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. # https://youtu.be/Vas20qurw28
  2. import pyaudio
  3. import speech_recognition as sr
  4. import os, sys
  5. import pyttsx3
  6. import random
  7. import webbrowser
  8. import psutil
  9. import time
  10. import subprocess as sp
  11.  
  12. os.system("title docController")
  13.  
  14. def closeAll():
  15.     os.system("taskkill /f /im winword.exe")
  16.     os.system("taskkill /f /im XLVIEW.EXE")
  17.     os.system("taskkill /f /im excel.exe")
  18.     os.system("taskkill /f /im powerpnt.exe")
  19.     os.system("taskkill /f /im wordpad.exe")
  20.     os.system("taskkill /f /im vlc.exe")
  21.     os.system("taskkill /f /im msedge.exe")
  22.     os.system("taskkill /f /im Microsoft.Photos.exe")
  23.    
  24.  
  25.    
  26.    
  27. def pidFullList(typProcess):
  28.     a = []
  29.     for process in psutil.process_iter():
  30.         if process.name() == typProcess:
  31.             a.append(process.pid)
  32.     return a
  33.  
  34. def pidGet(typProcess):
  35.     global listPid
  36.     a1 = pidFullList(typProcess)
  37.     os.startfile("D:/ТШО курсы/сертифы/Certificate project.xlsm")
  38.     os.startfile("D:/ТШО курсы/сертифы/Certificate project.xlsm")
  39.     time.sleep(1)
  40.     a2 = pidFullList(typProcess)
  41.     listPid=list(set(a2) - set(a1))
  42.     print(listPid)
  43.     return listPid
  44.  
  45. def closeByPid():
  46.     #https://ab57.ru/cmdlist/taskkill.html
  47.     checkVarible()
  48.     if listPid != None:
  49.         for element in listPid:
  50.             print(element)
  51.             os.system("taskkill /PID "+str(element))
  52.  
  53. def checkVarible():
  54.     global listPid
  55.     try:
  56.         listPid
  57.     except NameError:
  58.         print("ничего не открыто  внутри")
  59.         listPid = None
  60.  
  61.    
  62.  
  63. while True:
  64.     choice = int(input("closeAll - 0, OpenDoc - 12, CloseDoc - (-12): "))
  65.     if choice == 0:
  66.         closeAll();print(" +close")
  67.     elif choice == 12:
  68.         listPid = pidGet("EXCEL.EXE");print(" +OpenDoc")
  69.     elif choice == -12:  
  70.         closeByPid();print(" +CloseDoc")
  71.     else:
  72.         print(" - no comand")
  73.  
Advertisement
Add Comment
Please, Sign In to add comment