Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using this script

VB
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\cimv2")

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("Select * From __InstanceCreationEvent Within 5 Where " _
    & "Targetinstance Isa 'CIM_DirectoryContainsFile' and " _
    & "TargetInstance.GroupComponent= " _
    & "'Win32_Directory.Name=""c:\\\\scripts""'")

Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop




i can monitor only files which has been create inside the c:\\script folder.

if i create any folders inside the script folder its not monitoring.
and also if i create any files inside that newfolder also its not monitoring.
Posted
Updated 9-Jan-13 3:04am
v2
Comments
[no name] 9-Jan-13 9:07am    
Have you tried FileSystemWatcher?
@BangIndia 9-Jan-13 9:08am    
No. how do with that.
Sergey Alexandrovich Kryukov 9-Jan-13 9:33am    
This is from .NET library. Do you use C++, native, or C++/CLI?

Please see my answer. With .NET, it would be much simpler...
—SA
[no name] 7-Feb-13 7:27am    
Aimdharma, did you got answer for C/C++ here.. if yes kindly post it..

1 solution

You don't have to use WMI. Consider this: http://msdn.microsoft.com/en-us/library/aa365465%28VS.85%29.aspx[^].

[EDIT]

In response to a follow-up question:

Change journal? All I know is this: http://msdn.microsoft.com/en-us/library/aa363798%28v=vs.85%29.aspx[^].

—SA
 
Share this answer
 
v2
Comments
fjdiewornncalwe 9-Jan-13 9:41am    
+5. The right choice.
Sergey Alexandrovich Kryukov 9-Jan-13 9:52am    
Thank you, Marcus.
—SA
@BangIndia 23-Jan-13 11:09am    
see this link.. http://blogs.msdn.com/b/oldnewthing/archive/2011/08/12/10195186.aspx
readdirectoyex is not a good approuch
@BangIndia 23-Jan-13 11:08am    
see this link.. http://blogs.msdn.com/b/oldnewthing/archive/2011/08/12/10195186.aspx
readdirectoyex is not a good approuch
@BangIndia 23-Jan-13 11:08am    
see this link.. http://blogs.msdn.com/b/oldnewthing/archive/2011/08/12/10195186.aspx
readdirectoyex is not a good approuch

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900