Have CMD file eject usb drive ... and prevent Windows from making that drive available during boot

Discussion in 'General Discussion' started by jepollard, May 16, 2017.

  1. jepollard

    jepollard

    Joined:
    May 16, 2017
    Messages:
    8
    Likes Received:
    0
    I have a CMD file that does a backup of selected files from my hard drive to a USB drive of my choice (the CMD file asks me to enter the drive letter).

    I'd like to have the CMD file automatically eject the USB drive when the backup is complete. And I would like to prevent Windows from automatically "recognizing" that drive the next time I boot Windows.
    [Currently, I manually eject the drive after the backup, but when I turn on the computer the next day, Windows "un-ejects" it. I'd like the drive to remain inaccessible until I manually remove it and re-insert it.]

    Is this possible. If so, how?
     
    jepollard, May 16, 2017
    #1
    1. Advertisements

  2. jepollard

    TrainableMan ^ The World's First ^ Moderator

    Joined:
    May 10, 2010
    Messages:
    9,078
    Likes Received:
    1,586
    Location:
    PA, USA
    There is C++ code you could use to eject it but I don't know how you would do it with a DOS cmd.

    As for it not recognizing it on boot that would pretty much defeat the point of a USB drive. USB drives are recognized when inserted or powered up otherwise how would things like USB keyboards or mice work?
     
    TrainableMan, May 31, 2017
    #2
    1. Advertisements

  3. jepollard

    jepollard

    Joined:
    May 16, 2017
    Messages:
    8
    Likes Received:
    0
    Thank you for your response.

    I will have to investigate your C++ link; I'm not a C programmer.

    I don't understand how a user chosen "option" to prevent a specific USB device from being automatically made accessible after being "ejected" defeats any point of USB device capability. For my specific purpose, it is the inability to do so that is defeating my specific purpose.

    I am only wishing to have the ability to prevent Windows from automatically recognizing a device that has been "ejected" - but not physically removed. Do users actually "eject" USB mice and keyboards?

    Once the device has been ejected, it is no longer accessible by Windows, even if it has not been physically removed ... until Windows is rebooted. So what I am asking is just the option for Windows to fail to recognize the device again (even after re-boot) ... until I physically remove it and re-insert it.

    Since I suspect that most users are already "removing" the USB device that they "eject", it's hard for me to see what harm allowing users to have that "ejected" (but not removed) device "optionally" treated as unavailable, even after re-booting, would cause.

    Thanks again for responding.
     
    jepollard, Jun 1, 2017
    #3
  4. jepollard

    TrainableMan ^ The World's First ^ Moderator

    Joined:
    May 10, 2010
    Messages:
    9,078
    Likes Received:
    1,586
    Location:
    PA, USA
    The computer is powered off, once it is powered on again, some power is sent to the USB hubs & any connected devices and they are noticed, just the same as any USB device gets noticed once it gets power as you plug it in.

    As for your statement, "it's hard for me to see what harm allowing users to have that "ejected" (but not removed) device "optionally" treated as unavailable" ... I'm not saying there would be any harm at all; I'm simply saying it isn't designed that way. There is no on/off switch stored of the removable disk volumes you ejected.

    All you are really doing with your "eject" is making sure it is safe to remove the device by confirming the write buffer is clear & no files are in use. The purpose is so that you can remove it w/o data loss or crashing a program using a file there. Windows removes ejected drives from the available volumes and they no longer show in Windows Explorer but the device is still known to the computer because it still has power. In fact, to prove the drive is still there, here is an article on making the USB drive reappear in Windows Explorer from The Windows Club (The article mentions Win8 but it should function the same w/ win7).

    So if the USB device cycles off & on, either by power being removed & added to the device or by disable/enable of the USB port then the drive will be seen again as long as it is in the computer.

    There is software you can buy that does block USB flash drives; many corporations use programs like it to prevent employees inserting flash drives. You may be able to utilize something like that with some effort but I still don't believe it is exactly what you are looking to do.
     
    TrainableMan, Jun 1, 2017
    #4
  5. jepollard

    jepollard

    Joined:
    May 16, 2017
    Messages:
    8
    Likes Received:
    0
    "The purpose is so that you can remove it w/o data loss or crashing a program using a file there".

    I knew that.

    But I didn't expect this,"[t]here is no on/off switch stored of the removable disk volumes you ejected", to be true. Windows knows the device is in an "ejected" state and not available after I click "Eject", but "forgets" that when rebooting.

    I had hoped to be able to programmatically (via a CMD file) make a USB drive "temporarily" inaccessible to anyone not physically able to remove and insert the drive. That offered the protection I wanted, and Eject seemed to be a logical first step to my desired end result. I understand now that my hope was in vain.

    " ... I still don't believe it is exactly what you are looking to do".

    From what I can glean from that page, I don't think it does what I want either.

    As I recall, someone there did note that it can be a pain to remove/re-insert USB drives, and that is what triggered my desire: I'd rather wait until I need the drive again - which could be several days ... or a week or more - to have to remove it, when I can also immediately re-insert it. Only have to deal with the USB drive once, rather than twice.

    Thanks for your help; it looks like I will have to remove the drive right after the backup, and re-insert when I next need it.
     
    jepollard, Jun 1, 2017
    #5
  6. jepollard

    TrainableMan ^ The World's First ^ Moderator

    Joined:
    May 10, 2010
    Messages:
    9,078
    Likes Received:
    1,586
    Location:
    PA, USA
    If it's a desktop you could just leave it turned on. I used to leave mine on for a week or more, I just turned off my monitor.
     
    TrainableMan, Jun 2, 2017
    #6
  7. jepollard

    jepollard

    Joined:
    May 16, 2017
    Messages:
    8
    Likes Received:
    0
    FWIW:
    I'm trying a slightly different approach.

    I purchased a 7 port USB hub that has a separate on/off switch for each port. When a port is turned off, Windows does not recognize that port when it boots. I can make the port available to Windows again by just turning the power on for that specified port. This avoids the need to ever remove or re-insert the device.

    While not quite what I originally wanted, it is close (and better for the fact I never need remove the devices). If there was a way to programmatically turn the power off to each switch individually (but no way to programmatically turn that power back on), I think I'd have a better solution than what I originally wanted.

    Anyway, thanks again for your help.
     
    jepollard, Jun 6, 2017
    #7
  8. jepollard

    John700

    Joined:
    Jun 17, 2017
    Messages:
    18
    Likes Received:
    0
    1. you can use commands to eject drives, like remove drive.exe (Uwe Sieber - www.uwe-sieber.de) to eject external drives in the current session

    2. making it non-bootable: eject has nu further effect than un-using it in the current session. When you restart Windows, it wil act as normal again. If it is a boot disk, it will boot. (If the BIOS order allows that). Changing BIOS from Windows is hard, so the best solution to me looks like : a bootable drive is nothing else than a file named fileX or fileY. Windows just looks for certain named files, then boots. No ? So; if you rename some or all of these files, Windows will say : not a bootable drive, and hopefully just skip that drive.
     
    John700, Jun 18, 2017
    #8
  9. jepollard

    jepollard

    Joined:
    May 16, 2017
    Messages:
    8
    Likes Received:
    0
    ------------------------------------------------------------------
    Thanks for trying to help.
    As you say, and as I was previously told in this discussion, there is no way to tell Windows not to recognize a USB drive that is plugged in when Windows boots.
    So, as noted in my previous post, I am taking a somewhat different approach: I bought a USB hub that allows me to turn off the power to each port individually. When a port has no power, Windows can't recognize a device plugged into that port. I think that's the best I can do.
     
    jepollard, Jun 19, 2017
    #9
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. auutumn

    Issues with DigitalRiver and making a boot DVD

    auutumn, Oct 23, 2009, in forum: General Discussion
    Replies:
    2
    Views:
    1,935
  2. TreadLight

    Boot Manager Missing/Boot from USB Drive

    TreadLight, Nov 26, 2009, in forum: Windows 7 Support
    Replies:
    1
    Views:
    30,008
  3. teg1545

    move from cmd.exe 32 bit to cmd.exe 64 bit

    teg1545, Oct 12, 2010, in forum: Windows 7 Support
    Replies:
    2
    Views:
    3,502
    teg1545
    Oct 12, 2010
  4. Jackson

    Making Windows explorer show file extentions.

    Jackson, Aug 28, 2011, in forum: alt.windows7.general
    Replies:
    15
    Views:
    1,175
    Gene E. Bloch
    Aug 30, 2011
  5. jaguar85

    Classpnp.sys, black screen during startup repair and during boot

    jaguar85, Dec 20, 2011, in forum: Crashes, BSODs and Debugging
    Replies:
    2
    Views:
    3,335
  6. l.hilger

    .bat file and two commands in one cmd line

    l.hilger, Dec 20, 2012, in forum: Windows 7 Support
    Replies:
    9
    Views:
    2,992
    TrainableMan
    Dec 23, 2012
  7. JHaley1971

    How to start and install Windows 7 updates and suggested updates from CMD

    JHaley1971, Jan 30, 2013, in forum: Installation, Setup and Updates
    Replies:
    1
    Views:
    2,229
    oliverpowell
    Mar 18, 2013
  8. Maurizio

    is there any "force eject USB flash even it's un use" ?

    Maurizio, Feb 9, 2013, in forum: alt.windows7.general
    Replies:
    3
    Views:
    871
    Philip Herlihy
    Feb 9, 2013
Loading...