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

Joined
May 16, 2017
Messages
8
Reaction score
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?
 

TrainableMan

^ The World's First ^
Moderator
Joined
May 10, 2010
Messages
9,353
Reaction score
1,587
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?
 
Joined
May 16, 2017
Messages
8
Reaction score
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.
 

TrainableMan

^ The World's First ^
Moderator
Joined
May 10, 2010
Messages
9,353
Reaction score
1,587
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.
 
Joined
May 16, 2017
Messages
8
Reaction score
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.
 

TrainableMan

^ The World's First ^
Moderator
Joined
May 10, 2010
Messages
9,353
Reaction score
1,587
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.
 
Joined
May 16, 2017
Messages
8
Reaction score
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.
 
Joined
Jun 17, 2017
Messages
18
Reaction score
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?
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.
 
Joined
May 16, 2017
Messages
8
Reaction score
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.
------------------------------------------------------------------
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.
 

Ask a Question

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. After that, you can post your question and our members will help you out.

Ask a Question

Top