Hibernate – Standby: Timed LockWorkStation

There is an option for Windows to prompt for a password when the computer resumes from Standby or Hibernatation – for me this option is usually not convenient for tablet/laptop use.

Do you really care that the system suspended (after a few minutes on a ‘long-life’ power setting…)? – or do you care how long it has been suspended? I tend to care about how long it has been suspended. I like my Toshiba R10 tablet to go into Standby fairly quickly when I am running on batteries (for long meetings…), if my tablet has only been suspended for a few minutes I do not want to be forced to put in a password when it resumes (especially when I need to quickly take notes or look up information!). On the other hand, if my computer has been Suspended (either Hibernate or Standby) for 45 minutes it seems 100% appropriate to be prompted for a password since it is likely I am either not around or not paying any attention to it.

I have not found a way to trigger a password prompt based on the amount of time Suspended so I wrote a small application – WARNING THIS SOFTWARE IS LARGELY UNTESTED AND VERY BETA:

Suspend Timed Lock – Application

Suspend Timed Lock – VS 2005 Project (Source)

This application sits in the system tray – it records the time that the system Suspends and on Resume looks at the number of minutes that have elapsed. If the elapsed number of minutes is greater than a number of minutes set by the user the workstation is locked.

This is not meant as a hard-core high-security solution, I am sure that there are many trivial ways to bypass it on Resume – no chance this would foil serious hackers. On the other hand, it makes casual data theft/snooping much harder (especially combined with programs like TrueCrypt), while letting the system resume without a password in situations where it is useful and convenient – the idea here is to strike a useful balance of security and convenience…

Some things I learned –
This is a really simple application. It really comes down to just two lines of code (the source is available for download to see these in context):

AddHandler SystemEvents.PowerModeChanged, AddressOf powerModeTracker
(which is an easy way to catch the Suspend event)

Declare Function LockWorkStation Lib “user32.dll” () As Boolean
(used to lock the workstation)

I thought about (and am still thinking about) implementing an option to record the time of a Montior Power Down event. I tested this idea with this code:

Private Const WM_SYSCOMMAND As System.Int32 = &H112
Private Const SC_MONITORPOWER = &HF170

    Protected Overrides Sub WndProc(ByRef m As Message)
     Debug.Print("Hit WndProc")
     If m.Msg = WM_SYSCOMMAND Then
      Debug.Print("Hit WM_SYSCOMMAND")
        If m.WParam.ToInt32 = SC_MONITORPOWER Then
         Debug.Print("Hit SC_MONITORPOWER")
        End If
      End If

    End Sub

The code functioned as I expected, but not when the form was hidden or minimized! When hidden or minimized the form never seems to recieve SC_MONITORPOWER. Hopefully I am missing something simple (comments giving me a clue are very welcome – this feels like something I will laugh at myself about when I know the solution), I think it would be a nice additional option.


2 thoughts on “Hibernate – Standby: Timed LockWorkStation

  1. Aaron

    Awesome stuff. I’d guess that plenty of others would be interested in your solution.

    Did you know that you can set a “grace period” for the password prompt after the screen saver activates it? I found the option in the TweakUI powertoy. Not quite the same thing as you’ve got here, but useful as well.

  2. cmiles Post author

    I did not know about the grace period for the screen saver password prompt – very cool! I will have to check it out, I did not spend too much time poking into the screen saver possibilities, prob. because I don’t run one on my laptop.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s