48

On my work computer I have two USB hard drives that I use rarely. They have a power save mode that sends them into sleep after a couple of minutes of them being idle.

Whenever I open a context menu on a file, the drives are woken up (most likely caused by the "send to" handler). So I eject the drive, but I can't find a way to get it back, other than unplugging and replugging it in.

Is there a way to unmount the drives, and then remount them only when I actually need them? (On Windows 7 Ultimate.)

Pacerier
  • 26,733
  • 82
  • 197
  • 273
Oliver Salzburg
  • 86,445
  • 63
  • 260
  • 306
  • If it's any help, I summarized all option within my answer for [this question](https://superuser.com/questions/677114/deny-application-access-to-hard-drive-or-volume-in-windows-7) – Albin Sep 25 '18 at 22:45

4 Answers4

47

Remove the drive letters using mountvol or diskmgmt.msc. Without a drive letter, they won't appear under Computer or Send To.

mountvol Q: /p

Using /p will actually dismount the device. On older Windows versions, you only have /d, which only unassigns the drive letter, but keeps the volume mounted.

Reassign when needed, using the volume ID printed by mountvol:

mountvol Q: \\?\Volume{1be3da43-6602-11e0-b9e6-f11e1c50f5b5}\

You can also mount the volume on an empty folder (Unix style) using the same tools:

mkdir C:\fs\backup-disk
mountvol C:\fs\backup-disk \\?\Volume{1be3da43-6602-11e0-b9e6-f11e1c50f5b5}\

All these operations require Administrator privileges.


(In fact, you might even be able to directly use the volume ID in your backup scripts, without having to mount it anywhere. For example, \\?\Volume{1be3da43-6602-11e0-b9e6-f11e1c50f5b5}\projects instead of Q:\projects.)

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • 6
    By the way, is that GUID tied to the device? Will it be the same if I plug the device into another Windows machine? Is it even static between reboots on the same machine? – Oliver Salzburg Jun 11 '11 at 21:53
  • 2
    @OliverSalzburg: The volume GUID is tied to that specific volume, and persists after reboots. (It has to, in order for persistent drive letter assignments and filesystem mounts to work.) But unfortunately it's local to the machine. (As far as I know, Windows has no way to reference volumes by label or filesystem UUID yet.) – u1686_grawity Jun 12 '11 at 08:39
  • 2
    @OliverSalzburg: Although if you browse the Object Manager using [WinObj](http://technet.microsoft.com/en-us/sysinternals/bb896657), you'll find more symlinks pointing to the same `\Device\...`: for example, to access my iPod I can use `E:\Music` or `\\?\STORAGE#RemovableMedia#7&bec343e&0&RM#{53f5630a-b6bf-11d0-94f2-00a0c91efb8b}\Music`... But again, those appear to be variable between machines. – u1686_grawity Jun 12 '11 at 08:50
  • 3
    Is this really the same as unmounting in UNIX? On a UNIX box, once the volume is umounted, it's safe to rip it out of the computer. (Maybe it'll make your SATA bus upset, if you don't have the appropriate hardware support for that, and you might need to reboot, but you won't lose any data.) If you can still access the disk as \\?\Volume{...}, doesn't that mean the filesystem is still available to the OS, and therefore might have unflushed data in write cache and so on? – Glyph Feb 08 '13 at 06:22
  • 1
    @Glyph: UNIX is dead – better compare this to Linux or another modern operating system. On Linux, a single fs can be mounted on multiple places, usually using "bind mounts", and *all* of them must be unmounted to detach a filesystem. On Windows, you could also say that the OS has a few automatic mountpoints (`\\?\Volume{…}`), and the `mountvol` command manages *additional* mountpoints. So the filesystem remains attached as long as there is *at least one* mountpoint – even when you remove all user-facing mountpoints from `mountvol`'s list, you still have the internal `\\?\Volume{…}` one. – u1686_grawity Feb 08 '13 at 11:29
  • 1
    @Glyph: (The *device nodes* on Windows would be `\\.\Device\HarddiskVolume23` in the [NT namespace](http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx).) /// Also, Windows does have a few functions to unmount volumes completely – the [FSCTL_LOCK_VOLUME](http://msdn.microsoft.com/en-us/library/windows/desktop/aa364575%28v=vs.85%29.aspx) and [FSCTL_DISMOUNT_VOLUME](http://msdn.microsoft.com/en-us/library/windows/desktop/aa364562%28v=vs.85%29.aspx) ioctls. They are only effective for as long as the program is running, however. – u1686_grawity Feb 08 '13 at 11:35
  • @grawity: Is there any way to issue those IOCTLs from a command-line or graphical administration tool? – Glyph Feb 11 '13 at 23:55
  • The /P option is described to additionaly "dismount the volume", compared to /D. Can someone elaborate on that? Does it unmount it "more" than just /D? – David Balažic Nov 21 '13 at 22:46
  • 3
    @DavidBalažic: `/D` only removes the drive letter (or path) assignment. Dismounting means detaching *all* such assignments, as well as closing the filesystem itself. Remember that Windows mounts all filesystems by default on the `\\?\Volume{…}` paths, and therefore regular `mountvol` usage only adds/removes additional ones (like `mount --bind /x /y` on Linux). – u1686_grawity Nov 22 '13 at 16:11
  • 3
    So if I want Windows to completely "let go" of the volume, I have to use /P ? To get the same effect as _umount_ on *nix? Using /D removes one letter/path assignment while the volume actually stays mounted? – David Balažic Nov 22 '13 at 20:10
  • 2
    @DavidBalažic: Yes. – u1686_grawity Nov 22 '13 at 20:13
  • @grawity, then the answer should updated, as it is misleading. Although it does answer the body of the question, but not its title. – David Balažic Nov 23 '13 at 00:22
  • @grawity, Regarding *"you might even be able to directly use the volume ID in your backup scripts"*, How would you get `\\?\Volume{...}\ ` to work? It doesn't seem to work in file explorer, and `cmd` also complains *" does not support UNC paths as current directories."*. – Pacerier May 03 '15 at 14:04
  • 1
    @Pacerier: Well, that applies to `cmd` specifically, not to external tools like robocopy or rsync. And even in cmd it's limited to using UNC _as current directory_ – you can very well do `dir \\foo\bar` or `copy \\foo\bar \\baz\qux`. – u1686_grawity May 03 '15 at 15:44
  • @grawity, I don't think I'm following here.... I can't seem to get it working in `cmd`: http://i.stack.imgur.com/m3uBr.png – Pacerier May 24 '15 at 15:24
6

Use DISKPART to set your disk offline
It will stay offline even after a restart or a new power on

Use DISKPART to set it back online

This can be done in scripts

command file to put disk 2 offline:

Offline.cmd

 echo list disk              > c:\windows\temp\namexxxx.none
 echo select disk 2         >> c:\windows\temp\namexxxx.none
 echo offline disk          >> c:\windows\temp\namexxxx.none
 echo exit                  >> c:\windows\temp\namexxxx.none
 diskpart /s c:\windows\temp\namexxxx.none
 erase c:\windows\temp\namexxxx.none
 pause

command file to put disk 2 online:

Online.cmd

 .
 echo select disk 2 ........
 echo online disk ......
 .

Execute as administrator

Opoedre
  • 61
  • 1
  • 2
5

The correct answer is using the /P parameter to mountvol (see the comments in the accepted answer to understand why /D is not enough) but that only applies to recent windows versions (NT kernel version 6 and up).

The devcon utility as described in this answer works across all NT versions

Costin Gușă
  • 704
  • 8
  • 20
1

CMD doesn't have a function implemented to eject USB drives. It can, however call Win COM Objects which have the needed functions implemented eg. Shell.Application via powershell, VBS, JS, etc.

Alternatively (if you know how to interface with USB host), you may create an executable from Win CMD to send commands directly to USB or via (Windows) OS, then call/run it from CMD (similar to writing a COM object or Powershell commandlets).

In powershell from CMD:

powershell "$driveEject = New-Object -comObject Shell.Application; $driveEject.Namespace(17).ParseName(\"E:\").InvokeVerb(\"Eject\"); start-sleep -s 3"

Ejecting disk via powershell also requires it to be unplugged & plugged back in to be mounted again. Otherwise the disk can just be unmounted so it's inaccessible until it's mounted again by either mountvol or diskpart.

eg. with mountvol:

REM unmount
mountvol e: /D or /P
REM mount for access
mountvol e: \\?\Volume{device GUID in hex with hyphens}\

mountvol allows mounting devices to a folder eg. C:\fakedisk\ as well as a drive letter.

eg. With diskpart:

REM unmount
(
echo select volume 3
echo remove letter=e dismount
) | diskpart

REM mount again for access
(
echo select volume 3
echo assign letter=e
) | diskpart

Tested in Win 10 cmd

Zimba
  • 1,051
  • 11
  • 15