I have, on my PC, the screensaver Mystify.scr which is triggered when my computer has been idle for 15 minutes. I have a "watchdog" service (actually) script that checks when this screensaver is triggered and if so, deletes all BAK files from my D: drive. The script should exit once the computer becomes active (when the screensaver process exits). Here's my script:
| 1 |
sHost = "." |
| 2 |
Set oWMIService = GetObject("winmgmts:\\" & sHost & "\root\cimv2") |
| 3 |
Set oEventSource = oWMIService.ExecNotificationQuery _ |
| 4 |
("SELECT * FROM __InstanceOperationEvent" & _ |
| 5 |
" WITHIN 10 WHERE TargetInstance ISA 'Win32_Process'") |
| 6 |
Do While True |
| 7 |
Set oEventObject = oEventSource.NextEvent() |
| 8 |
If oEventObject.TargetInstance.Name = "Mystify.scr" Then |
| 9 |
Set colItems = oWMIService.ExecQuery _ |
| 10 |
("Select * from Win32_OperatingSystem") |
| 11 |
For Each oItem in colItems |
| 12 |
DelFiles("D:") |
| 13 |
Next |
| 14 |
End If |
| 15 |
Loop |
| 16 |
|
| 17 |
Sub DelFiles(strDrv) |
| 18 |
Set colFiles = oWMIService.ExecQuery _ |
| 19 |
("Select * from CIM_DataFile Where Drive = '" & _ |
| 20 |
strDrv & "' and Extension = 'bak'") |
| 21 |
For Each objFile in colFiles |
| 22 |
objFile.Delete |
| 23 |
Next |
| 24 |
End Sub |
Regards,
Salvador Manaois III
C|EH MCSE MCSA MCITP|Server/Enterprise Admin
Bytes & Badz : http://badzmanaois.blogspot.com