Results 1 to 28 of 28

Thread: [RESOLVED] USB Storage device

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Resolved [RESOLVED] USB Storage device

    hello!
    how would i know if the USB Storage device is inserted
    and determine the drive letter?

    tnx
    *****************
    VB6,PHP,VS 2005

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: USB Storage device

    GetLogicalDrives()
    I don't live here any more.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: USB Storage device

    GetLogicalDrives()

    thnk you for this info.
    but could you explain further?
    *****************
    VB6,PHP,VS 2005

  4. #4
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: USB Storage device

    I have not clearly remember the way of doing it in Java. I'll give a little code segment on C#. Try do convert it refereeing the Java documentation.

    Code:
    using System;
    
    class Sample 
    {
        public static void Main() 
        {
        String[] drivesLetters = Environment.GetLogicalDrives();
        Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drivesLetters));
        }
    }
    This will print out as GetLogicalDrives: A:\, C:\, D:\ and so on.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: USB Storage device

    this is my orginal question:

    how would i know if the USB Storage device is inserted
    and determine the drive letter?

    it can be D:, E:, F: and etc.

    i just want to know if it is inserted and i want to know what drive letter it is?
    *****************
    VB6,PHP,VS 2005

  6. #6
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: USB Storage device

    Hmm, for that your requirement my code is not the one. Have you read the documentation? Sorry I don't have an idea about it...
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: USB Storage device

    i already searched in the web almost a day but still i can't find any solution
    *****************
    VB6,PHP,VS 2005

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: USB Storage device

    1/2
    Code:
    using DetectDrive;
    using System.IO;
    
    namespace SimpleDetector
    {
        public partial class Form1 : Form
        {
            private DriveDetector driveDetector = null;
    
            public Form1()
            {
                InitializeComponent();
                driveDetector = new DriveDetector(this);
                driveDetector.DeviceArrived += new DriveDetectorEventHandler(OnDriveArrived);
                driveDetector.DeviceRemoved += new DriveDetectorEventHandler(OnDriveRemoved);
                driveDetector.QueryRemove += new DriveDetectorEventHandler(OnQueryRemove);
            }
    
            // Called by DriveDetector when removable device in inserted 
            private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
            {
                // Report the event in the listbox.
                // e.Drive is the drive letter for the device which just arrived, e.g. "E:\\"
                listBox1.Items.Clear();
                string s = "Drive arrived " + e.Drive;
                listBox1.Items.Add(s);
                MessageBox.Show(e.Drive.ToString());
    
                // If you want to be notified when drive is being removed (and be able to cancel it), 
                // set HookQueryRemove to true 
                if ( checkBoxAskMe.Checked )   
                    e.HookQueryRemove = true;                 
            }
    
            // Called by DriveDetector after removable device has been unpluged 
            private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
            {
                // TODO: do clean up here, etc. Letter of the removed drive is in e.Drive;
                
                // Just add report to the listbox
                listBox1.Items.Clear();
                string s = "Drive removed " + e.Drive;
                listBox1.Items.Add(s);
            }
    
            // Called by DriveDetector when removable drive is about to be removed
            private void OnQueryRemove(object sender, DriveDetectorEventArgs e)
            {
                // Should we allow the drive to be unplugged?
                if (checkBoxAskMe.Checked)
                {
                    if (MessageBox.Show("Allow remove?", "Query remove",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        e.Cancel = false;       // Allow removal
                    else
                        e.Cancel = true;        // Cancel the removal of the device  
                }
            }
    
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);        // call default p
                
                if (driveDetector != null)
                {
                    driveDetector.WndProc(ref m);
                }
            }
    
            // User checked the "Ask me before drive can be disconnected box"        
            private void checkBoxAskMe_CheckedChanged(object sender, EventArgs e)
            {
                if (checkBoxAskMe.Checked)
                {
                    // Is QueryRemove enabled? 
                    // If not, we will enable it for the drive which is selected 
                    // in the listbox. 
                    // If the listbox is empty, no drive has been detected yet so do nothing now.
                    if (!driveDetector.IsQueryHooked && listBox1.Items.Count > 0)
                    {
                        if (listBox1.SelectedItem == null)
                        {
                            MessageBox.Show("Please choose the drive for which you wish to be asked in the list (select its message).");
                            checkBoxAskMe.Checked = false;
                            return;
                        }
    
                        bool ok = false;
                        string s = (string)listBox1.SelectedItem;
                        int n = s.IndexOf(':');
                        if (n > 0)
                        {
                            s = s.Substring(n - 1, 3);  // Gets drive letter from the message, (e.g. "E:\\") 
    
                            // Tell DriveDetector to monitor this drive
                            ok = driveDetector.EnableQueryRemove(s);
                        }
    
                        if (!ok)
                            MessageBox.Show("Sorry, for some reason notification for QueryRemove did not work out.");
    
                    }
    
                }
                else
                {
                    if (driveDetector.IsQueryHooked)
                        driveDetector.DisableQueryRemove();
                }                        
            }
    *****************
    VB6,PHP,VS 2005

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: USB Storage device

    2/2
    [CODE]
    using System.Windows.Forms; // required for Message
    using System.Runtime.InteropServices; // required for Marshal
    using System.IO;
    using Microsoft.Win32.SafeHandles;

    namespace DetectDrive
    {

    // Delegate for event handler to handle the device events
    public delegate void DriveDetectorEventHandler(Object sender, DriveDetectorEventArgs e);

    public class DriveDetectorEventArgs : EventArgs
    {
    public DriveDetectorEventArgs()
    {
    Cancel = false;
    Drive = "";
    HookQueryRemove = false;
    }
    public bool Cancel;

    public string Drive;
    public bool HookQueryRemove;

    }

    class DriveDetector : IDisposable
    {

    public event DriveDetectorEventHandler DeviceArrived;
    public event DriveDetectorEventHandler DeviceRemoved;
    public event DriveDetectorEventHandler QueryRemove;

    public DriveDetector(Control control)
    {
    mFileToOpen = null;
    mDeviceNotifyHandle = IntPtr.Zero;
    mRecipientHandle = control.Handle;
    mCurrentDrive = "";
    }
    public DriveDetector(Control control, string FileToOpen)
    {
    mFileToOpen = FileToOpen;
    mDeviceNotifyHandle = IntPtr.Zero;
    mRecipientHandle = control.Handle;
    mCurrentDrive = "";
    }
    public bool IsQueryHooked
    {
    get
    {
    if (mDeviceNotifyHandle == IntPtr.Zero)
    return false;
    else
    return true;
    }
    }

    public string HookedDrive
    {
    get
    {
    return mCurrentDrive;
    }
    }

    public FileStream OpenedFile
    {
    get
    {
    return mFileOnFlash;
    }
    }
    public bool EnableQueryRemove(string fileOnDrive)
    {
    if (fileOnDrive == null || fileOnDrive.Length == 0)
    throw new ArgumentException("Drive path must be supplied to register for Query remove.");
    if ( fileOnDrive.Length == 2 && fileOnDrive[1] == ':' )
    fileOnDrive += '\\'; // append "\\" if only drive letter with ":" was passed in.

    if (mDeviceNotifyHandle != IntPtr.Zero)
    {
    RegisterForDeviceChange(false, null);
    }

    if (!File.Exists(fileOnDrive))
    mFileToOpen = null; // use any file
    else
    mFileToOpen = fileOnDrive;

    RegisterQuery(Path.GetPathRoot(fileOnDrive));
    if (mDeviceNotifyHandle == IntPtr.Zero)
    return false; // failed to register

    return true;
    }

    public void DisableQueryRemove()
    {
    if (mDeviceNotifyHandle != IntPtr.Zero)
    {
    RegisterForDeviceChange(false, null);
    }
    }

    public void Dispose()
    {
    RegisterForDeviceChange(false, null);
    }

    #region WindowProc
    public void WndProc(ref Message m)
    {
    int devType;
    char c;

    if (m.Msg == WM_DEVICECHANGE)
    {
    // WM_DEVICECHANGE can have several meanings depending on the WParam value...
    switch (m.WParam.ToInt32())
    {

    //
    // New device has just arrived
    //
    case DBT_DEVICEARRIVAL:

    devType = Marshal.ReadInt32(m.LParam, 4);
    if (devType == DBT_DEVTYP_VOLUME)
    {
    DEV_BROADCAST_VOLUME vol;
    vol = (DEV_BROADCAST_VOLUME)
    Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));

    // Get the drive letter
    c = DriveMaskToLetter(vol.dbcv_unitmask);

    if ( tempDeviceArrived != null )
    {
    DriveDetectorEventArgs e = new DriveDetectorEventArgs();
    e.Drive = c + ":\\";
    tempDeviceArrived(this, e);

    // Register for query remove if requested
    if (e.HookQueryRemove)
    {
    // If something is already hooked, unhook it now
    if (mDeviceNotifyHandle != IntPtr.Zero)
    {
    RegisterForDeviceChange(false, null);
    }

    RegisterQuery(c + ":\\");
    }
    } // if has event handler


    }
    break;
    case DBT_DEVICEQUERYREMOVE:

    devType = Marshal.ReadInt32(m.LParam, 4);
    if (devType == DBT_DEVTYP_HANDLE)
    {
    DriveDetectorEventHandler tempQuery = QueryRemove;
    if (tempQuery != null)
    {
    DriveDetectorEventArgs e = new DriveDetectorEventArgs();
    e.Drive = mCurrentDrive; // drive which is hooked
    tempQuery(this, e);

    // If the client wants to cancel, let Windows know
    if (e.Cancel)
    {
    m.Result = (IntPtr)BROADCAST_QUERY_DENY;
    }
    else
    {
    // Close the handle so that the drive can be unmounted
    if (mFileOnFlash != null)
    {
    mFileOnFlash.Close();
    mFileOnFlash = null;
    }
    }

    }
    }
    break;


    //
    // Device has been removed
    //
    case DBT_DEVICEREMOVECOMPLETE:

    devType = Marshal.ReadInt32(m.LParam, 4);
    if (devType == DBT_DEVTYP_VOLUME)
    {
    devType = Marshal.ReadInt32(m.LParam, 4);
    if (devType == DBT_DEVTYP_VOLUME)
    {
    DEV_BROADCAST_VOLUME vol;
    vol = (DEV_BROADCAST_VOLUME)
    Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));
    c = DriveMaskToLetter(vol.dbcv_unitmask);

    DriveDetectorEventHandler tempDeviceRemoved = DeviceRemoved;
    if (tempDeviceRemoved != null)
    {
    DriveDetectorEventArgs e = new DriveDetectorEventArgs();
    e.Drive = c + ":\\";
    tempDeviceRemoved(this, e);
    }

    }
    }
    break;
    }

    }

    }
    #endregion
    *****************
    VB6,PHP,VS 2005

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: USB Storage device

    #region Private Area

    private FileStream mFileOnFlash = null;

    private string mFileToOpen;
    private IntPtr mDeviceNotifyHandle;

    private IntPtr mRecipientHandle;
    private string mCurrentDrive;


    // Win32 constants
    private const int DBT_DEVTYP_DEVICEINTERFACE = 5;
    private const int DBT_DEVTYP_HANDLE = 6;
    private const int BROADCAST_QUERY_DENY = 0x424D5144;
    private const int WM_DEVICECHANGE = 0x0219;
    private const int DBT_DEVICEARRIVAL = 0x8000; // system detected a new device
    private const int DBT_DEVICEQUERYREMOVE = 0x8001; // Preparing to remove (any program can disable the removal)
    private const int DBT_DEVICEREMOVECOMPLETE = 0x8004; // removed
    private const int DBT_DEVTYP_VOLUME = 0x00000002; // drive type is logical volume

    private void RegisterQuery(string drive)
    {
    bool register = true;

    if (mFileToOpen == null)
    {
    // If client gave us no file, let's pick one on the drive...
    mFileToOpen = GetAnyFile(drive);
    if (mFileToOpen.Length == 0)
    return; // no file found on the flash drive
    }
    else
    {

    if (mFileToOpen.Contains(":"))
    {
    string tmp = mFileToOpen.Substring(3);
    string root = Path.GetPathRoot(drive);
    mFileToOpen = Path.Combine(root, tmp);
    }
    else
    mFileToOpen = Path.Combine(drive, mFileToOpen);
    }


    try
    {
    mFileOnFlash = new FileStream(mFileToOpen, FileMode.Open);
    }
    catch (Exception)
    {
    // just do not register if the file could not be opened
    register = false;
    }

    if (register)
    {
    RegisterForDeviceChange(true, mFileOnFlash.SafeFileHandle);
    mCurrentDrive = drive;
    }
    }

    private void RegisterForDeviceChange(bool register, SafeFileHandle fileHandle)
    {
    if (register)
    {
    DEV_BROADCAST_HANDLE data = new DEV_BROADCAST_HANDLE();
    data.dbch_devicetype = DBT_DEVTYP_HANDLE;
    data.dbch_reserved = 0;
    data.dbch_nameoffset = 0;
    data.dbch_handle = fileHandle.DangerousGetHandle(); //Marshal. fileHandle;
    data.dbch_hdevnotify = (IntPtr)0;
    int size = Marshal.SizeOf(data);
    data.dbch_size = size;
    IntPtr buffer = Marshal.AllocHGlobal(size);
    Marshal.StructureToPtr(data, buffer, true);

    mDeviceNotifyHandle = Native.RegisterDeviceNotification(mRecipientHandle, buffer, 0);
    }
    else
    {
    if (mDeviceNotifyHandle != IntPtr.Zero)
    Native.UnregisterDeviceNotification(mDeviceNotifyHandle);
    mDeviceNotifyHandle = IntPtr.Zero;
    mCurrentDrive = "";
    if (mFileOnFlash != null)
    {
    mFileOnFlash.Close();
    mFileOnFlash = null;
    }
    }

    }

    private static char DriveMaskToLetter(int mask)
    {
    char letter;
    string drives = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    // 1 = A
    // 2 = B
    // 4 = C...
    int cnt = 0;
    int pom = mask / 2;
    while (pom != 0)
    {
    // while there is any bit set in the mask
    // shift it to the righ...
    pom = pom / 2;
    cnt++;
    }

    if (cnt < drives.Length)
    letter = drives[cnt];
    else
    letter = '?';

    return letter;
    }

    private string GetAnyFile(string drive)
    {
    string file = "";
    // First try files in the root
    string[] files = Directory.GetFiles(drive);
    if (files.Length == 0)
    {
    // if no file in the root, search whole drive
    files = Directory.GetFiles(drive, "*.*", SearchOption.AllDirectories);
    }

    if (files.Length > 0)
    file = files[0]; // get the first file

    // return empty string if no file found
    return file;
    }
    #endregion


    #region Native Win32 API
    private class Native
    {
    // HDEVNOTIFY RegisterDeviceNotification(HANDLE hRecipient,LPVOID NotificationFilter,DWORD Flags);
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr RegisterDeviceNotification(IntPtr hRecipient, IntPtr NotificationFilter, uint Flags);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern uint UnregisterDeviceNotification(IntPtr hHandle);

    }

    // Structure with information for RegisterDeviceNotification.
    [StructLayout(LayoutKind.Sequential)]
    public struct DEV_BROADCAST_HANDLE
    {
    public int dbch_size;
    public int dbch_devicetype;
    public int dbch_reserved;
    public IntPtr dbch_handle;
    public IntPtr dbch_hdevnotify;
    public Guid dbch_eventguid;
    public long dbch_nameoffset;
    //public byte[] dbch_data[1]; // = new byte[1];
    public byte dbch_data;
    public byte dbch_data1;
    }

    // Struct for parameters of the WM_DEVICECHANGE message
    [StructLayout(LayoutKind.Sequential)]
    public struct DEV_BROADCAST_VOLUME
    {
    public int dbcv_size;
    public int dbcv_devicetype;
    public int dbcv_reserved;
    public int dbcv_unitmask;
    }
    #endregion

    }
    }
    [/CODE]

    before my head breaks...
    i think i found what im lookin for, my next step now is how could i search all files including subfolders (considering i don't know the folder names)in the USB storage since it is obvious that i already know the drive letter?

    below is helpful but you must specify the folder names
    foreach (string filepath in System.IO.Directory.GetFiles(@"C:\folder" , "*.txt", System.IO.SearchOption.AllDirectories))


    sorry for many texts i just wanna share the code for future reference.
    *****************
    VB6,PHP,VS 2005

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: USB Storage device

    below is helpful but you must specify the folder names
    foreach (string filepath in System.IO.Directory.GetFiles(@"C:\folder" , "*.txt", System.IO.SearchOption.AllDirectories))
    *****************
    VB6,PHP,VS 2005

  12. #12
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: USB Storage device

    Nice work.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: USB Storage device

    for searching drive with directories i found this on microsoft's website
    void DirSearch(string sDir)
    {
    try
    {
    foreach (string d in Directory.GetDirectories(sDir))
    {
    foreach (string f in Directory.GetFiles(d, txtFile.Text))
    {
    lstFilesFound.Items.Add(f);
    }
    DirSearch(d);
    }
    }
    catch (System.Exception excpt)
    {
    Console.WriteLine(excpt.Message);
    }
    }

    tnx to you people!

    "don't do to other people if you don't want to experience what you did"
    *****************
    VB6,PHP,VS 2005

  14. #14
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: USB Storage device

    Quote Originally Posted by basti42

    "don't do to other people if you don't want to experience what you did"
    But the most of the people do.

    Anyway I have few question on that your code, and still I'm working with them. Later I'll put them here.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: USB Storage device

    ok tnx, anyway that's why i'm doing this project is because
    we issued several usb's our point is contents on the usb must be legal files
    e.g. .xls, ppt, .doc, .odt and other than that it will not permitted.
    *****************
    VB6,PHP,VS 2005

  16. #16
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: USB Storage device

    Actually my final year project is somewhat similar to that, have to work with all possible drivers, including USB as well.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Wink Re: USB Storage device

    ioc, i know you can do it

    this world would turn smoothly without barbarians
    *****************
    VB6,PHP,VS 2005

  18. #18
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: [RESOLVED] USB Storage device

    I have a one question.

    Do you know how can I detect the port, I mean weather it is com 1 or 2 port, USB port, etc
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: [RESOLVED] USB Storage device

    i don't exactly how to detect in COM ports, as an example is when you insert a device in COM1 or COM2 nothing happens right? so where could i find the trigger?
    but in your code you can specify whether it is COM1 or COM2, about in USB see the attachment i've searched this for you,
    hope it would help.
    Attached Files Attached Files
    *****************
    VB6,PHP,VS 2005

  20. #20
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: [RESOLVED] USB Storage device

    Quote Originally Posted by basti42
    so where could i find the trigger?
    Even me come across with this same issue, and have no idea about it.


    Anyway thanks for your attachment, I'll try to work it out.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  21. #21
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: USB Storage device

    Quote Originally Posted by basti42
    this is my orginal question:

    how would i know if the USB Storage device is inserted
    and determine the drive letter?

    it can be D:, E:, F: and etc.

    i just want to know if it is inserted and i want to know what drive letter it is?
    i always used this function:
    Code:
    Declare Function GetDriveType& Lib "kernel32" Alias "GetDriveTypeA" (ByVal _
    nDrive As String)
    you pass it a drive letter and colon and it returns a number depending on what kind of drive it is.
    If you run it with a loop through every drive letter, you will be able to pick out removable storage easy.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  22. #22
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: USB Storage device

    Quote Originally Posted by Lord Orwell
    it returns a number depending on what kind of drive it is.

    How

    Can you explain a little more.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  23. #23
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [RESOLVED] USB Storage device

    that's what the function is for.
    [quote:=Desaware Visual Basic Programmer's Guide to the Win32 api]
    The GetdriveType function has a return value that is a Long—Zero if the drive cannot be identified. One if the specified directory does not exist. One of the constants DRIVE_REMOVABLE, DRIVE_FIXED, DRIVE_REMOTE, DRIVE_CDROM or DRIVE_RAMDISK specifying the drive type on success
    [/quote]

    call it like this:
    msgbox getdrivetype("c:")
    If you pass it an invalid drive, the function returns a 1.
    Here are the values of the constants:
    Code:
    Public Const DRIVE_CDROM = 5
    Public Const DRIVE_FIXED = 3
    Public Const DRIVE_RAMDISK = 6
    Public Const DRIVE_REMOTE = 4
    Public Const DRIVE_REMOVABLE = 2
    A jump drive should be listed as 2. A floppy disk or tape drive is also a 2, but you can eliminate them easily by not checking A or B. I've never used a zip drive, so i don't know what they have for a drive letter, so it might not stop them. But filesystem checks can work too.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  24. #24
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: [RESOLVED] USB Storage device

    Hmm, that will help for my project.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  25. #25
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [RESOLVED] USB Storage device

    It's what i used in a project of mine. I created a program in VB6 to do all of this:
    1. read a cd or dvd directory structure as deep as you want to and store it as a searchable file
    2. allow you to add notes on each file and add a description for the disk.
    3. allow you to navigate the stored directory tree like in explorer.
    4. search for keywords both in the entire file list or just in the description of the disk
    5. automatically assign id numbers for the read disks for you to mark on the disk.

    Program works fine and i still have it, although i will be the first to admit it has a very unusual user interface. If you right-click on a button, a context menu (which is really a hidden frame) appears with options for that button.
    The part i use it for is this: when you right click the import button, among other options is a image combo loaded with a list of all your cd drives to choose from.
    Attached Images Attached Images  
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  26. #26
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: [RESOLVED] USB Storage device

    Quote Originally Posted by Lord Orwell
    Program works fine and i still have it, although i will be the first to admit it has a very unusual user interface. If you right-click on a button, a context menu (which is really a hidden frame) appears with options for that button.
    The part i use it for is this: when you right click the import button, among other options is a image combo loaded with a list of all your cd drives to choose from.

    This part make sense to me. Do you have any idea, how that hidden frame is work. I mean any special logic there.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  27. #27
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [RESOLVED] USB Storage device

    no special logic. It was murder to design in the IDE though. It just simply showed the frame on right click, and the frame had a close-x in the corner.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  28. #28
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: [RESOLVED] USB Storage device

    Quote Originally Posted by Lord Orwell
    frame had a close-x in the corner.
    I think that is, great. Anyway,
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width