Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Monitor which process is deleting a file

Status
Not open for further replies.

Sunny4Ever

IS-IT--Management
Nov 6, 2002
77
GB
I support an application and one of the users is loosing log files which are being deleted by an unknown process. I need a script to monitor for file deletion events and then relate this back to the process which is doing this. I have the first part of the puzzle which is a WMI event consumer however I can only echo the name of the file when it is deleted and not the process responsible. Any scripting Guru out there that can suggest how to get the required functionallity?

-S

What I have so far:


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceDeletionEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""D:\\\\temp""'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top