summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-12-10 12:52:48 +0100
committerJose M. Guisado <jguisado@soleta.eu>2021-12-10 12:56:50 +0100
commit355e6caad360f2a5acedb125a3f421b8aee7a2e0 (patch)
treecf5b4e54b0eac6d8bbb942c42f3c69982e8b505a
parent1601ad9b298ccefa1a71ae9ccfb939c73a5fc0ec (diff)
#1065 windows: use shutdown for poweroff and reboot operations
Running ogClient as a service (non interactive user) breaks poweroff and reboot using ExitWindowsEx function in user32.dll. Spawn a subshell using os.system and use the 'shutdown' command instead. This is a terminating command, we don't need fine grain from subprocess module.
-rw-r--r--src/windows/ogOperations.py10
1 files changed, 2 insertions, 8 deletions
diff --git a/src/windows/ogOperations.py b/src/windows/ogOperations.py
index 6bc5e93..d20b52c 100644
--- a/src/windows/ogOperations.py
+++ b/src/windows/ogOperations.py
@@ -19,10 +19,6 @@ 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
@@ -75,14 +71,12 @@ class OgWindowsOperations:
raise NotImplementedError
def poweroff(self):
- user32 = ctypes.WinDLL('user32')
systray_p.terminate()
- user32.ExitWindowsEx(EWX_POWEROFF, 0x0)
+ os.system('shutdown -s -t 0')
def reboot(self):
- user32 = ctypes.WinDLL('user32')
systray_p.terminate()
- user32.ExitWindowsEx(EWX_REBOOT, 0x0)
+ os.system('shutdown -r -t 0')
def shellrun(self, request, ogRest):
cmd = request.getrun()