A USB project - please help! How can I do it?

Hi,
I recently downloaded 'Visual Basic 2005 Express Edition BETA 2'
I've read some of the help files, watched some tutorials and am pretty familiar (but still new) to the software. Big Smile
I was wondering if anyone could tell me if and how I could go about making this software which processes information likes so -

- User inserts a USB storage device.

- User clicks button.

- Application silently searches for filename named 'JE1.txt' on USB storage device.

- If the filename is found on the device the application opens a simple 'messagebox' with 'Correct' or something in it that I can change. If the filename is not found a mesagebox with 'Incorrect' appears.

Any way you think I can build this Or will I need other software
Thanks in advance,
James Big Smile

PS. I'm not that experienced so please keep it simple!


Answer this question

A USB project - please help! How can I do it?

  • Les Thompson

    Thanks for your help but ... when I copy an paste this code LOADS of errors/bugs come up. I can't run it - where should I put it - what am I doing wrong !
    I am using Visual Basic 2005 Express edition and it comes up with loads of problems with the code!
    Where do I put it in - anyone !
    Please!
    But thanks for your help anyway! I'm bad at this, remember, so please can someone tell me how to get this working Maybe just send me a solution folder for it
    Please help
    Thanks again,
    James
    JAMESEVS <AT> GMAIL <DOT> COM

  • Macy-Mike

    The following code is used to detect when a new USB storage device is plugged in. I am aware that this is not as you say 'keeping it simple' for a beginner, but when I find some time I'll re-write this for you to make it more simple and to do exactly what you asked for. However, I figured that for now this was better than nothing. You can try experimenting with this code, and the MSDN library is always there if you don't understand anything.



    using System;
    using System.Management;

    class WMIEvent
    {
      public static void Main()
      {
        WMIEvent we = new WMIEvent();
        ManagementEventWatcher w = null;
        WqlEventQuery q;
        ManagementOperationObserver observer = new ManagementOperationObserver();

        // Bind to local machine
        ManagementScope scope = new ManagementScope("root\\CIMV2");
        scope.Options.EnablePrivileges = true; //set required privilege

        try

        {
          q = new WqlEventQuery();
          q.EventClassName = "__InstanceOperationEvent";
          q.WithinInterval = new TimeSpan(0,0,3);
          q.Condition = @"TargetInstance ISA 'Win32_DiskDrive' ";

          w = new ManagementEventWatcher(scope, q);
          w.EventArrived += new EventArrivedEventHandler(we.DiskEventArrived);
          w.Start();

          Console.ReadLine(); // block main thread for test purposes
        }
        catch(Exception e)
        {
          Console.WriteLine(e.Message);
        }
        finally

        {
          w.Stop();
        }
      }

      public void DiskEventArrived(object sender, EventArrivedEventArgs e)
      {
        //Get the Event object and display its properties (all)
        foreach(PropertyData pd in e.NewEvent.Properties)
        {
          ManagementBaseObject mbo = null;

          if(( mbo = pd.Value as ManagementBaseObject) != null)
          {
            Console.WriteLine("--------------Properties------------------");

            foreach(PropertyData prop in mbo.Properties)
              Console.WriteLine("{0} - {1}", prop.Name, prop.Value);
          }
        }
      }
    }


     


    Good Luck!

    Tell me if this helps.

  • A USB project - please help! How can I do it?