Click here to Skip to main content
11,931,584 members (67,826 online)
Rate this:
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""'")
    Set objLatestEvent = colMonitoredEvents.NextEvent
    Wscript.Echo objLatestEvent.TargetInstance.PartComponent

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
Shameel 9-Jan-13 9:07am
Have you tried FileSystemWatcher?
aimdharma 9-Jan-13 9:08am
No. how do with that.
This is from .NET library. Do you use C++, native, or C++/CLI?

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

1 solution

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

Solution 2

You don't have to use WMI. Consider this:[^].


In response to a follow-up question:

Change journal? All I know is this:[^].

Marcus Kramer 9-Jan-13 9:41am
+5. The right choice.
Thank you, Marcus.
aimdharma 23-Jan-13 11:09am
see this link..
readdirectoyex is not a good approuch
aimdharma 23-Jan-13 11:08am
see this link..
readdirectoyex is not a good approuch
aimdharma 23-Jan-13 11:08am
see this link..
readdirectoyex is not a good approuch
Sergey Alexandrovich Kryukov 23-Jan-13 11:59am
It depends. Is the only problem that it won't invoke callback until file handle is closed? I know.
aimdharma 23-Jan-13 23:56pm
msdn suggest the Change Journals to use. pls suggest on this.
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.)

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...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2015
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