Click here to Skip to main content
11,803,019 members (77,517 online)
Rate this: bad
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 1:50am
Edited 9-Jan-13 3:04am
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...
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
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 at 9-Jan-13 9:41am
+5. The right choice.
Sergey Alexandrovich Kryukov at 9-Jan-13 9:52am
Thank you, Marcus.
aimdharma at 23-Jan-13 11:09am
see this link..
readdirectoyex is not a good approuch
aimdharma at 23-Jan-13 11:08am
see this link..
readdirectoyex is not a good approuch
aimdharma at 23-Jan-13 11:08am
see this link..
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.
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.)

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

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

  Print Answers RSS
0 KrunalRohit 356
1 OriginalGriff 335
2 CPallini 270
3 F-ES Sitecore 270
4 Sergey Alexandrovich Kryukov 234
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,735
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web04 | 2.8.151002.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