From 2e9e5bcb3d1522a7cd7053db7f7080a9e959e46b Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Fri, 19 Nov 2021 11:13:05 +0100 Subject: #1065 windows: add poweroff and reboot Uses ExitWindowsEx from user32.dll. Library is loaded using ctypes. See https://stackoverflow.com/a/50824776 --- src/windows/ogOperations.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/windows') diff --git a/src/windows/ogOperations.py b/src/windows/ogOperations.py index 0af7250..baafbd9 100644 --- a/src/windows/ogOperations.py +++ b/src/windows/ogOperations.py @@ -7,6 +7,7 @@ # (at your option) any later version. import os +import ctypes import subprocess from subprocess import CalledProcessError import multiprocessing as mp @@ -18,6 +19,10 @@ from pystray import Icon, Menu, MenuItem from src.ogRest import ThreadState +EWX_POWEROFF=0x00000008 +EWX_REBOOT=0x00000002 + + def _create_default_image(): """ Creates a default image for the tray icon. Use in case @@ -69,10 +74,14 @@ class OgWindowsOperations: raise NotImplementedError def poweroff(self): + user32 = ctypes.WinDLL('user32') systray_p.terminate() + user32.ExitWindowsEx(EWX_POWEROFF, 0x0) def reboot(self): + user32 = ctypes.WinDLL('user32') systray_p.terminate() + user32.ExitWindowsEx(EWX_REBOOT, 0x0) def shellrun(self, request, ogRest): cmd = request.getrun() -- cgit v1.2.3-18-g5258