Guest User

Untitled

a guest
Jul 12th, 2026
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.39 KB | None | 0 0
  1. # /// script
  2. # requires-python = ">=3.10"
  3. # dependencies = [
  4. #     "pywin32",
  5. # ]
  6. # ///
  7.  
  8. import win32api
  9. import win32security
  10. import ctypes
  11. import sys
  12.  
  13. def enable_privilege_pywin32():
  14.     try:
  15.         # Открываем токен текущего процесса для изменения привилегий
  16.         h_token = win32security.OpenProcessToken(
  17.             win32api.GetCurrentProcess(),
  18.             win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY
  19.         )
  20.         # Находим LUID нужной привилегии
  21.         luid = win32security.LookupPrivilegeValue(None, "SeProfileSingleProcessPrivilege")
  22.         # Включаем её (атрибут SE_PRIVILEGE_ENABLED)
  23.         win32security.AdjustTokenPrivileges(h_token, 0, [(luid, win32security.SE_PRIVILEGE_ENABLED)])
  24.         return True
  25.     except Exception as e:
  26.         print(f"Ошибка активации через pywin32: {e}")
  27.         return False
  28.  
  29. def clear_standby_list(command_code):
  30.     ntdll = ctypes.windll.ntdll
  31.     ntdll.NtSetSystemInformation.argtypes = [ctypes.c_int, ctypes.c_void_p, ctypes.c_ulong]
  32.     ntdll.NtSetSystemInformation.restype = ctypes.c_uint32
  33.  
  34.     command = ctypes.c_ulong(command_code)
  35.     status = ntdll.NtSetSystemInformation(80, ctypes.byref(command), ctypes.sizeof(command))
  36.     print(f"Код ответа от ядра для команды {command_code}: {hex(status)}")
  37.     return status == 0
  38.  
  39. if __name__ == "__main__":
  40.     if not enable_privilege_pywin32():
  41.         print("Не удалось получить права уровня ядра. Попробуйте запустить консоль от Администратора.")
  42.         sys.exit(1)
  43.  
  44.     print("Очистка Standby List...")
  45.  
  46.     # 4 - Очистить весь кэш (standbylist)
  47.     if clear_standby_list(4):
  48.         print("[ОК] Standby List успешно очищен.")
  49.     else:
  50.         print("[Ошибка] Не удалось очистить Standby List. Возможно, список уже пуст.")
  51.  
  52.     # 5 - Очистить низкоприоритетный кэш (priority0standbylist)
  53.     if clear_standby_list(5):
  54.         print("[ОК] Низкоприоритетный Standby List очищен.")
  55.     else:
  56.         print("[Ошибка] Не удалось очистить низкоприоритетный Standby List.")
  57.  
Advertisement
Add Comment
Please, Sign In to add comment