From: Phillip Gawlowski Date: 2010-12-29T01:04:37+09:00 Subject: Re: can ruby script detect 'pc lock', 'pc unlock' instances ? On Tue, Dec 28, 2010 at 3:11 PM, Vijay Ramane wrote: > Hello i need urgent help > How we can manage/detect instances like pc lock or pc unlock via ruby > script Use Windows' Event Log instead (Account auditing has to be enabled via group policy in Active Directory or locally on the machine for this to work, otherwise you'd've to hook into explorer or svchost to gather the locking messages). > e.g > 1). If i start my pc then script will automatically start until i > log-off. > 2). If i lock my pc script will start counting time until i unlock pc. > 3). then it will shows whole days lock-unlock time No need to, since Windows can keep track of Logon / Logoff events (4624, 4634 are the respective Event IDs). Just interface with the Security event log, and parse it (or export it as XML, *then* parse it). Windows doesn't directly provide a Lock/Unlock message, but if there was no shutdown of the system between the logoff and logon events, it's rather certain that it was an (un)locking Apparently, the win32-eventlog gem[0] can make parsing event logs easier. Note: I haven't tested it, so I have no idea if it works with Ruby 1.9 or so, and the documentation doesn't say anything about this, either. [0] http://rubyforge.org/docman/view.php/85/1738/EventLog.html -- Phillip Gawlowski Though the folk I have met, (Ah, how soon!) they forget When I've moved on to some other place, There may be one or two, When I've played and passed through, Who'll remember my song or my face.