Is there a way to run a VBS script when someone unlocks there computer? For
example, if someone leaves for lunch, they typically will lock their
computer screen. Is there a way to run a script when the computer screen
becomes unlocked?

Re: Unlock by Torgeir

Torgeir
Fri Mar 11 15:57:42 CST 2005

Dave wrote:

> Is there a way to run a VBS script when someone unlocks there
> computer? For example, if someone leaves for lunch, they
> typically will lock their computer screen. Is there a way to
> run a script when the computer screen becomes unlocked?
Hi

If you enable auditing of successful logon events, you will find
entries for computer unlocking in the security event log.

Auditing of logon events has to be enabled on the computer via Local
Security Policy or possibly domain level if in a domain. Then you can
trigger your script for the following event in the security log:

Event ID 538 containing Logon Type 7

HOW TO: Audit User Access of Files, Folders, and Printers in Windows XP
http://support.microsoft.com/default.aspx?scid=kb;en-us;310399


The following script will detect computer unlock events:

'--------------------8<----------------------

Set objWMIServices = GetObject _
("WinMgmts:{impersonationLevel=impersonate,(Security)}\\.\root\cimv2")
Set LoggedEvents = objWMIServices.ExecNotificationQuery _
("Select * from __instancecreationevent within 2 where " _
& "TargetInstance isa 'Win32_NTLogEvent' " _
& "And TargetInstance.EventCode = 538")

' loop forever
Do
Set objLatestEvent = LoggedEvents.NextEvent
strEventMsg = objLatestEvent.TargetInstance.Message

If InStr(1, strEventMsg, _
"Logon Type:" & vbTab & "7", vbTextCompare) > 0 Then

WScript.Echo "Computer was unlocked!"
End If
Loop

'--------------------8<----------------------



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: Unlock by Dave

Dave
Mon Mar 14 07:54:50 CST 2005

I will review the script. Thanks Torgeir!


"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:ul0StXoJFHA.2648@TK2MSFTNGP14.phx.gbl...
> Dave wrote:
>
> > Is there a way to run a VBS script when someone unlocks there
> > computer? For example, if someone leaves for lunch, they
> > typically will lock their computer screen. Is there a way to
> > run a script when the computer screen becomes unlocked?
> Hi
>
> If you enable auditing of successful logon events, you will find
> entries for computer unlocking in the security event log.
>
> Auditing of logon events has to be enabled on the computer via Local
> Security Policy or possibly domain level if in a domain. Then you can
> trigger your script for the following event in the security log:
>
> Event ID 538 containing Logon Type 7
>
> HOW TO: Audit User Access of Files, Folders, and Printers in Windows XP
> http://support.microsoft.com/default.aspx?scid=kb;en-us;310399
>
>
> The following script will detect computer unlock events:
>
> '--------------------8<----------------------
>
> Set objWMIServices = GetObject _
>
("WinMgmts:{impersonationLevel=impersonate,(Security)}\\.\root\cimv2")
> Set LoggedEvents = objWMIServices.ExecNotificationQuery _
> ("Select * from __instancecreationevent within 2 where " _
> & "TargetInstance isa 'Win32_NTLogEvent' " _
> & "And TargetInstance.EventCode = 538")
>
> ' loop forever
> Do
> Set objLatestEvent = LoggedEvents.NextEvent
> strEventMsg = objLatestEvent.TargetInstance.Message
>
> If InStr(1, strEventMsg, _
> "Logon Type:" & vbTab & "7", vbTextCompare) > 0 Then
>
> WScript.Echo "Computer was unlocked!"
> End If
> Loop
>
> '--------------------8<----------------------
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx