Results 1 to 14 of 14
  1. #1
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Unanswered: Need Help with USB code again - still can't find code to unplug detected drive

    I've exhausted my search on USB thumb keys. Here's what I need to do...

    Automatically detect the correct USB thumb key drive plugged in and somehow issue a "safe to remove" command so it can be safely unplugged. The problem is that on some notebooks we have, the USB thumb key is the D: drive and others it is the E: or F: drive. I have the rest of the code which autoruns and extracts a zipped (exe self-extracting file) on the USB thumb key but I need to issue the "Safe to Remove" when the code is done.

    The only thing I could find is a 3rd party program called QuickUnplug which I can utilize a command in a vb script such as: QuickUnplug D:/Close but it's not always the D: drive. Plus I'd like to avoid having to install any 3rd party apps.

    If anyone has links to any vb scripts or vb code to somehow issue a "safe to remove" command on the detected USB thumb key, I would greatly appreciate it. Everything I've found so far seems to indicate that this is difficult to do.
    Last edited by pkstormy; 06-08-07 at 23:00.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I'm not sure if this does what you want but it is still worth a look in.
    http://www.microsoft.com/downloads/d...DisplayLang=en
    Yes, I know it's .NET but come on - it may lead you down the right path. If I have understood right you simply need to stop all communications to the port - which I believe that example may help you do.
    HTH ~George
    George
    Home | Blog

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Thanks for the link George. I'll check it out. I'm getting desperate to try anything at this point.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Ok...this is getting really frustrating. I can usually find a way to do almost anything I need but I've been stuck on this for weeks and it shouldn't be that difficult.

    I just want to tap into the taskbar unplug icon and execute it for the USB thumb key. I want to do this with a little vb script code. There's gotta be a way. (I want to avoid using any sendkey commands.)
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    For a more in depth explanation (including some source code) for my previous link see: http://www.thaiio.com/prog-cgi/VBnetSerialPort.htm
    It utilizes a close command, which may or may not be what you need.

    This guy may also be worth talking to: http://odin.prohosting.com/kkoeman/

    Some code from here
    Code:
    COMPort.Close()
    Application.DoEvents()          ' Let all applications finish before the whole process goes to sleep.
    Sleep(500)                      ' Wait 0.5 second for port to close as this do not happen immediately.
    Suggesting that .Close() is all you need to stop data transfer?
    Last edited by gvee; 06-13-07 at 18:51.
    George
    Home | Blog

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Disappointingly found this link...
    http://modbus.control.com/user/1026223098/index_html

    EDIT: ignore
    George
    Home | Blog

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Wait for it....
    BAM!


    With added pow!
    George
    Home | Blog

  8. #8
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Good Bam and nice Pow. It'll help - thanks.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  9. #9
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Did this link not help with the unplugging?

    USB: Programmatically Unplug & Eject USB Device
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  10. #10
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    loquin,

    I'll take a look tomorrow at it at work. I may have overlooked that one. Thanks for the link!
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  11. #11
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    loquin,

    Thank you for the link. I tried the code. I kept getting an error which I might be able to fix. The thing I need it to do which it doesn't though is automatically detect which drive letter is plugged in. You have to tell it which drive to disconnect.

    Thank you though...I'm getting closer.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  12. #12
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    USB Eject

    I found the command I think I'm supposed to use: Cm_request_device_eject. But I can't find any vb sample code on how to utilize it. I can only find C++ code.

    Can anyone help?
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  13. #13
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Paul - if you don't mind an extra dependency, download removedrive, and shell it from your app, passing the drive letter/UNC pathname as a parameter. A bit kludgy, but it should work.
    Last edited by loquin; 07-10-07 at 20:03.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  14. #14
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Thanks for the reply again loquin. The problem is that I need to detect which drive is the usb thum key drive. Removedrive is kind of like QuickUnplug in that I have to supply a drive letter or UNC path in the command line. I'll take another look at it though.
    Last edited by pkstormy; 07-14-07 at 22:15.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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