Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C VBScript
Using this script
 
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 9-Jan-13 2:50am
Edited 9-Jan-13 4:04am
v2
Comments
Shameel at 9-Jan-13 9:07am
   
Have you tried FileSystemWatcher?
aimdharma at 9-Jan-13 9:08am
   
No. how do with that.
Sergey Alexandrovich Kryukov at 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
Pranit Kothari at 7-Feb-13 7:27am
   
Aimdharma, did you got answer for C/C++ here.. if yes kindly post it..

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v2
Comments
Marcus Kramer at 9-Jan-13 9:41am
   
+5. The right choice.
Sergey Alexandrovich Kryukov at 9-Jan-13 9:52am
   
Thank you, Marcus.
—SA
aimdharma at 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
aimdharma at 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
aimdharma at 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
Sergey Alexandrovich Kryukov at 23-Jan-13 11:59am
   
It depends. Is the only problem that it won't invoke callback until file handle is closed? I know.
—SA
aimdharma at 23-Jan-13 23:56pm
   
msdn suggest the Change Journals to use. pls suggest on this.
Sergey Alexandrovich Kryukov at 24-Jan-13 0:14am
   
What exactly about its use? It wasn't in your original question.
 
I don't know your purpose, so I have no idea why would you need to use journals at all. You may need it or not... Read the overview and see it, as you should know better, based on your purpose.
 
The link to the overview is available, please see after [EDIT] in my answer. If you need to know something specifically, I would advise to ask a separate question. (Make sure that your new question does not look like a re-post of the present question, to avoid an abuse reports for re-post. You and I know that this won't be a re-post, but someone might do it by mistake. Make it under distinct title.)
 
—SA
Sergey Alexandrovich Kryukov at 24-Jan-13 0:36am
   
Do you mean "how to use C..."?
But what would you need beyond information available in the overview I referenced? You probably need to be more specific, otherwise people will give you the same exact link...
—SA

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

  Print Answers RSS
0 OriginalGriff 290
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 149
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100