views:

60

answers:

3

How do I run .net code when a user unlocks their machine?

Windows versions: XP and 7

+5  A: 

This article looks perfect for you if you want to subscribe to the session lock/unlock events (e.g. how Messenger sets your status to away when you lock your PC).

http://blogs.msdn.com/b/shawnfa/archive/2005/05/17/418891.aspx

Alternatively, you can run a script on Windows 7 unlock as per this ServerFault question: http://serverfault.com/questions/148258/run-a-script-after-i-unlock-my-windows-session

Graphain
+3  A: 

Graphain is right that the article he suggests might help you.

On the chance that it doesn't, in a general sense you're looking for information on the ISensLogon interface, which is what allows you to monitor the events you're looking for. If you search for ISensLogon on google, you'll find a lot of articles about a lot of different ways to use it, at least one of which will probably help you.

Nick Bastin
+1  A: 

It's too bad you have to support XP as well. There's a nice scheduled task capability in Windows 7 that includes triggering it on workstation unlock. Would be just a few lines of code... and you could include things like "don't do it if the machine is on battery" too.

Kate Gregory