Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 22nd, 2004, 12:54 PM
Authorized User
Join Date: Jun 2003
Location: , , United Kingdom.
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
            "Service {0} has changed, State is {1}",

        //Cancel the subscription
        return 0;
Reply With Quote
  #2 (permalink)  
Old November 22nd, 2004, 06:55 PM
Kep Kep is offline
Authorized User
Join Date: Aug 2003
Location: Melbourne, VIC, Australia.
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts

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

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 08:25 AM.

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