Remove The ctypes.windll.user32.LockWorkStation and replace with an Message Box That wait for user to accept login. This avoid some tricky problems related to The lost-focus-app .So User can force app to quit ( Alt +F4 ) , Thing that we should avoid.