Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 22nd, 2004, 12:54 PM
Authorized User
 
Join Date: Jun 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Consuming WMI Events

I am trying to trigger a script when a user drops a file into a specific folder. I am not talking about a drop event within an application, I mean responding to the event at windows level.

To do this I need to write a class which consumes the windows event. This would probably need to be written as a service. The following code detects when a windows service changes, but I cannot find any info on how to respond to the folder changed event.

Any info in this area would be greatly appreciated.

-------------
using System;
using System.Management;

public class EventWatcherPolling
{
    public static int Main(string[] args)
    {
        // Create event query to be notified within 1 second of
        // a change in a service
        WqlEventQuery query = new WqlEventQuery("__InstanceModificationEvent", new TimeSpan(0,0,1), "TargetInstance isa \"Win32_Service\"");

        // Initialize an event watcher and subscribe to events
        // that match this query
        ManagementEventWatcher watcher = new ManagementEventWatcher(query);

        // Block until the next event occurs
        // Note: this can be done in a loop if waiting for
        // more than one occurrence
        ManagementBaseObject e = watcher.WaitForNextEvent();

        //Display information from the event
        Console.WriteLine(
            "Service {0} has changed, State is {1}",
            ((ManagementBaseObject)e["TargetInstance"])["Name"],
            ((ManagementBaseObject)e["TargetInstance"])["State"]);

        //Cancel the subscription
        watcher.Stop();
        return 0;
    }
}
__________________
Skin
 
Old November 22nd, 2004, 06:55 PM
Kep Kep is offline
Authorized User
 
Join Date: Aug 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There's a class System.IO.FileSystemWatcher. This class has several events for monitoring the file system. That should do what you require.

Kep.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in consuming Java Webservice using C# 2.0 chihcc .NET Web Services 0 August 28th, 2008 04:47 AM
consuming a webservice aklilu Classic ASP XML 0 May 13th, 2008 01:55 PM
consuming events from axWebBrowser roy VS.NET 2002/2003 3 March 9th, 2007 04:08 AM
Consuming Web Service edgtr .NET Web Services 0 November 1st, 2006 03:50 PM
Consuming and displaying XML busher XML 5 July 12th, 2005 12:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.