10

is there a way to mount and dismount a connected harddrive through a script or a simple utility software in Windows 8.1?

Basically, I have a hard drive in the ultrabay slot of my ThinkPad (instead of the dvd-drive). When booting the system, this hard drive is automatically being mounted and visible to me. Using the icon in the taskbar I can unmount it. Unfortunately, it is then only available again when I reboot the system.

So I wanted to ask if there is any command line script I can execute to dismount the drive and mount it again with another script without having to reboot?

This way I could call the unmount-script after booting, so the drive isn't always running, only when I need some stuff from it, I call the mount-script and then can access the files.

Would be great if anybody has any ideas on how to solve this! Thank you!

2
  • 1
    It does, but this requires me to lift up the ThinkPad, flip it over, use both hands to unlock and remove it and put it back in. Also, at the current state it automatically mounts the device when I boot up. Most of the times though, I don't need the contents of that HDD... – florianbaethge Jan 21 '14 at 15:20
  • OK, based on that I think read here. superuser.com/questions/121957/… or here raymond.cc/blog/… First thought is that maybe we can automate a devcon.exe session to automagically remount support.microsoft.com/kb/311272 – Knuckle-Dragger Jan 21 '14 at 15:23
9

DISCLAIMER: You are responsible for your own actions. I AM NOT responsible for any damage that you could possibly cause to your computer or laptop by trying anything outlined below.

Upon doing some research, I found THIS Instructable, detailing how to mount and unmount drives using the Windows command MOUNTVOL.

Tutorial

  1. First, open Command Prompt as Administrator.

  2. Run the command mountvol and take note of the volume name above the drive letter that you want to mount/unmount (e.g. \\?\Volume{########-####-####-####-############}\ )

  3. To unmount a drive, type mountvol [DriveLetter] /p. Be sure to replace [DriveLetter] with the letter assigned to the drive you wish to unmount. (For example, G:)

  4. To mount a drive, type mountvol [DriveLetter] [VolumeName]. Make sure you replace [DriveLetter] with the letter you wish to mount the drive to (for example, G:), and [VolumeName] with the volume name you noted in Step 2.

Batch Script

This is an example of two simple batch scripts you could use to mount and unmount the drive of your choice.

In order to make the batch files work, you will need to run them with administrative privileges, or the batch file will return an Access Denied error.

Unmounting:

@echo off

REM Be sure to change this to the drive you want to unmount! 
set drive=G:

echo Unmounting Drive...
mountvol %drive% /p
echo Drive Unmounted!

pause
exit

Mounting:

@echo off

REM Be sure to change this to the drive letter you want to mount the drive to!
set drive=G

REM Be sure to change this to the Volume Name of the drive you want to mount!
set volume=\\?\Volume{ae101d9f-7653-11e3-be83-8056f23387a6}\

:start
echo Mounting Drive...
mountvol %drive%: %volume%
echo Drive Mounted!
 
pause
exit

Make sure you alter the batch files at the top before running them, to make sure you are mounting/unmounting the correct drive.

Do NOT use /D, which only removes the drive letter assignment. Use /p. From mountvol /?:

/p          Removes the volume mount point from the specified directory,
            dismounts the volume, and makes the volume not mountable.
            You can make the volume mountable again by creating a volume
            mount point.
4
  • Did this work? Does it suit your needs? – joeeey Jan 29 '14 at 7:09
  • please also see superuser.com/questions/295913/… - there are two methods, mountvol and devcon – Costin Gușă May 10 '15 at 22:05
  • @joejoe31b apologies for a very naive question but, is there a way to use something other than the complicated GUID? Also is there a way to identify which are internal HDD and other types of storage? – KansaiRobot Feb 15 '18 at 7:39
  • What about dismounting EFI partition? Are you sure about using /p switch with that? – QMaster Oct 28 '19 at 17:54
2

Try this. I do not know whether this is what you want.

  1. Start diskpart.

    • Search for diskpart in the Start Menu or open Command Prompt and type in diskpart. You need administrative privileges to run diskpart.
  2. Type list volume in diskpart.

    • Note the volume number and name for the volume to be removed.
  3. Type select volume [drive letter (or drive number)].

    • For example: select volume G or select volume 5.
  4. Type remove letter [volume letter].

    • For example: remove letter G.

DONE!

To mount the volume, try the following:

  1. Follow the 1st and 2nd steps. Note that you can see the volume number and other details only, not the volume letter.

  2. Type assign letter [volume letter] or just assign. In here, replace the [volume letter] to any letter which you want to assign to the volume.

1
  • diskpart doesn't accept commands in CMD; it spawns it's own window for command input – Zimba Feb 5 at 14:49
1

From powershell we can mount/dismount via WMI methods.

Get-WmiObject -class Win32_Volume | where-object {$_.DeviceID -Like "\\?\Volume{########-####-####-####-############}\"} | foreach-object -process {$_.AddMountPoint("X:")}

To dismount, maybe this.

Get-WmiObject -class Win32_Volume | where-object {$_.DeviceID -Like "\\?\Volume{########-####-####-####-############}\"} | foreach-object -process {$_.Dismount()}

and here is how to find the GUID from powershell. Don't forget to edit the samples.

Get-WmiObject -class Win32_Volume | Select-Object DeviceID,DriveLetter 
1

You can use diskpart command line utility. It has "own" command line that accepts diskpart commands.

Here is article about this tool: link to technet.microsoft.com

You have to:

  • run diskpart.exe (it comes with Windows Vista/7/8, maybe some older too)
  • select disk with select disk n command (where n is disk number)
  • select partition with select partition n command (where n is partition number)
  • run assign command with parameters described below

assign [{letter=d|mount=path}] [noerr]

Assigns a drive letter or mount point to the volume with focus. If no drive letter or mount point is specified, then the next available drive letter is assigned. If the assigned drive letter or mount point is already in use, an error is generated.

By using the assign command, you can change the drive letter associated with a removable drive. You cannot assign drive letters to system volumes, boot volumes, or volumes that contain the paging file. You cannot assign a drive letter to an OEM partition or any GPT partition other than a basic data partition.

letter=d Specifies the drive letter that you intend to assign to the volume.

mount=path Specifies the mount point path that you intend to assign to the volume.

You can also use list disk, list partition or list volume to find your disk/partition/volume number.

Be careful what are you doing with that tool. It may be used to format drives.

5
  • Please expand upon this answer—link-only answers aren't particularly useful and can become invalid altogether if the linked content becomes unavailable. – bwDraco Dec 26 '14 at 19:26
  • Also, a link to general subject matter discussion doesn't really answer the question, it is just a suggestion for a place to start looking for an answer. For those kinds of links, it's particularly important to include the relevant portion in your answer. This kind of helpful suggestion should go in a comment. It looks like your answer may be deleted before you return from the holidays, so I'll move the info to a comment so that it isn't lost. – fixer1234 Dec 26 '14 at 21:21
  • Sorry guys, I thought that single "diskpart" word could be an answer. I added more details. – Kamil Dec 26 '14 at 21:46
  • I didn't expected that improving post will cause downvotes :) – Kamil Dec 26 '14 at 21:49
  • diskpart CANNOT unmount volumes – Costin Gușă May 10 '15 at 21:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.