Automatic logout with pyautogui?

I'm trying to automate logoff on a Windows system using Python. It should only logout like with win+l and not logoff like with shutdown -l.

I tried using pyautogui to press win+l, but for some reason it doesn't work. The shutdown /L and shutdown -l commands don't work either, as they kill the current user's process and close all processes, like a reboot would.

Thanks for any help!

(2 votes)
Loading...

Similar Posts

Subscribe
Notify of
2 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
GuteAntwort2021
1 year ago

Hello.

Try:

import ctypes

def logoff():
    user32 = ctypes.windll.user32
    user32.ExitWindowsEx(0x00000004, 0)

logoff()

This would unsubscribe to the user, but I cannot say what influence it has on processes.