tags:

views:

374

answers:

3

I want to write a small program that given a time (in minutes) as input, sleeps in the background for that time, and then forces a return to the "switch user screen" (equivalent to the Winkey+L combination) or logs off a user (may be another user logged in on the same machine).

What functions or libraries in Python could I use for this?

Edit:

  • I prefer just a return to the "Switch User" screen rather than actually logging off
  • Perhaps there's a simple Windows command to do this, which I could use
  • I have Windows XP if that's relevant
+1  A: 

Maybe you can use os.popen or subprocess to run windows command line for logout. I think logoff is the command. (According to this page)

Nadia Alramli
logoff sounds good, but I'd prefer just to lock out the user (like Winkey+L)
Yevgeny Doctor
A: 

I think you must use windows API, and run by python. use os.system('logoff'); (or logout, I forget) it is not tested, because I am using ubuntu now...

linjunhalida
+5  A: 

There seems to be a simple way of locking a computer using no Python libraries except for ctypes:

import ctypes
ctypes.windll.user32.LockWorkStation ()

Source: Tim Golden's Python Stuff

Jonas
looks good, I'll try it out
Yevgeny Doctor
Works great. Thanks.
Yevgeny Doctor