Log out or switch user on Windows using Python
I want to write a small program that has given a time (in minutes) as input, sleeps in the background for that time, and then makes it go back to the "switch screen" (equivalent to Winkey + L) or walks away from the user (maybe another user registered on the same computer).
What functions or libraries in Python can I use for this?
Edit:
- I only prefer going back to the Switch User screen rather than actually logging out.
- Maybe there is a simple Windows command for this that I could use
- I have Windows XP, if relevant
a source to share
There seems to be a simple way to lock a computer not using Python libraries other than ctypes:
import ctypes
ctypes.windll.user32.LockWorkStation ()
Source: Tim Golden Python
a source to share
Perhaps you can use os.popen or subprocess to run Windows command prompt to log out. I think logging out is a command. (According to this page )
a source to share
To switch users you can use this Win32 API function WTSDisconnectSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
#include "WtsApi32.h"
BOOL OsofemSwitchUser()
{
//Switch User
return WTSDisconnectSession(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, TRUE);
}
Don't forget to link it to the library WtsApi32.lib
.
This will take you back to the Switch User screen ... Hope this help ...
a source to share