WMI Event Watcher Task

  • I am using the WMI Event Watcher Task to watch for the arrival of a file.

    I have the following entered into the WqlQuerySource field in the WMI Event Watcher task.

    When I run it, the task turns yellow but does not find the file when it shows up (stays yellow until it times out).

    SELECT * FROM __InstanceCreationEvent WITHIN 10

    WHERE targetinstance isa "CIM_DirectoryContainsFile"

    AND TargetInstance.GroupComponent = "WIN32_Directory.Name=\"c:\\\\Users\\\\myfile\\\\TestFolder\\\\text.txt\""

    I know that there is a third-party File Watcher Task, but I'd like to know why this isn't working.

    Any suggestions would be greatly appreciated!

  • Hi,

    i believe you are looking for a particular file. but in ur code u r using "group component". we use group component for folder.

    try this

    SELECT * FROM __InstanceCreationEvent WITHIN 60 WHERE TargetInstance ISA 'CIM_DataFile' AND TargetInstance.Name = 'c:\\testData\\particularfile.txt'

    for folder try this

    SELECT * FROM __instancecreationevent WITHIN 60 WHERE TargetInstance ISA 'Cim_DirectoryContainsFile' AND TargetInstance.GroupComponent='Win32_Directory.Name="c:\\\\testData"'

    -----priyanko

  • I have problem with the same file watching. how to make package to run automatically when a file is placed in the folder and how to get new file which is being placed to the database.

    Please suggest the approach.

    Thanks.

  • Package has to be running already to see the file dropped.

    You could build a windows service to watch for the drop then start a package or you could poll the location and when a file is dropped start the package.

    But in all cases something has to be watching and start the package OR the package has to be running all the time and just be waiting.

    If you knew that the file was (almost) always dropped between 10-10:30am then you might schedule the package to start and 10 and either start watching that location or poll that location periodically. When the file appears process it, if it doesn't show within 30 minutes fail the package.

    CEWII

  • Thanks for the reply. I started learning ssis recently. I dont know visual basic 2008 also, How to create windows service to watch a folder and to get filenames being created.

    How to integrated that windows service to the package to run, so that once service starts and identifies files being created, how to make package to be run.

    Please provide steps how to proceed

    Thanks,

    Starterm

  • You would write the windows service in Visual Studio, it IS possible to do it in VS Express but the templates don't exist in that version but it can be done with some resources online. You can build a watcher using NTFS events or WMI.

    I will say that there is a lot that goes into a file watcher process. It would be easier to do a polled process, which goes out every 3-5 minutes and sees if the file is there and then starts the package. That is a WHOLE lot simpler..

    CEWII

  • Thanks for the reply, can you please explain that polled process how to do for file watching . I should check the folder if there are any new files created and load them into other folders but not checking a single file whether it exists or not in the folder specified. Please explain the steps.

    Thanks,

    Starterm

  • starterm (4/21/2010)


    Thanks for the reply, can you please explain that polled process how to do for file watching . I should check the folder if there are any new files created and load them into other folders but not checking a single file whether it exists or not in the folder specified. Please explain the steps.

    If you are looking for a known name in a known location it is very easy, you just periodically check for the name, if it is there you execute a SQL agent job.

    If you are trying to keep track of any new file at a number of locations it is harder. I tend to think that there are two paths (there maybe more). You either keep track of what is there or you take the whole list as new and move the files once processed.

    I usually like the second method because it is easier. In that case you look at the location and all files are new, once they are handled/processed they get moved somewhere else and therefore don't show up again. Easy.

    The first method though is more tricky. You have to keep track of the files at each location and when a file not previously seen appears you will know it. This method is trickier because you have to keep a list of files that are at each location, otherwise you won't know what has changed. I have heard it suggested that file dates could be used but I don't agree. If a file is copied or moved it retains its date, therefore I don't view this as a reliable method.

    Is this clearer for you?

    CEWII

  • Thanks for reply. I will try to implement

  • Elliott W (4/22/2010)


    starterm (4/21/2010)


    -- If a file is copied or moved it retains its date, therefore I don't view this as a reliable method.

    --

    CEWII

    If a file is copied, its Date Created changes, though you are right about file moves ...

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • I just don't trust file dates.. Call me paraoid, I have gotten burned too many times..

    CEWII

  • what do you suggest to proceed further with the problem?

    Thanks,

    starterm

  • There was a suggestion earlier in the thread that you just run the job frequently - every 5 minutes maybe - and process a file if it exists, otherwise exit. Is that solution viable for you? It is the easiest to implement - especially as you are new to the platform.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply