Mount and dismount hard drive through a script/software

8

2

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!

florianbaethge

Posted 2014-01-21T15:02:58.307

Reputation: 256

Question was closed 2015-05-11T18:08:38.753

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 – 2014-01-21T15:20:53.667

OK, based on that I think read here. http://superuser.com/questions/121957/how-to-un-eject-a-usb-flash-drive-eject-is-easy-safely-remove-hardware-b or here http://www.raymond.cc/blog/remount-ejected-or-safely-removed-usb-device-without-unplug-and-reinsert/ First thought is that maybe we can automate a devcon.exe session to automagically remount https://support.microsoft.com/kb/311272

– Knuckle-Dragger – 2014-01-21T15:23:14.207

Answers

8

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 up a Command Prompt as Administrator.
  2. Run the command mountvol and take note of the Volume Name above the drive letter you are wanting to mount/unmount (eg. \\?\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.

joeeey

Posted 2014-01-21T15:02:58.307

Reputation: 1 396

please also see http://superuser.com/questions/295913/how-to-mount-and-unmount-hard-drives-under-windows-the-unix-way/808926#808926 - there are two methods, mountvol and devcon

– Costin Gușă – 2015-05-10T22:05:59.493

@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 – 2018-02-15T07:39:03.553

What about dismounting EFI partition? Are you sure about using /p switch with that? – QMaster – 2019-10-28T17:54:03.797

Did this work? Does it suit your needs? – joeeey – 2014-01-29T07:09:06.947

2

Try this, I do not know whether this is what you want. Start diskpart( search for "diskpart" in start or open a cmd window and type in diskpart. You need administrative privilege to run diskpart)

  1. type "list volume" in diskpart, note the volume number and name for the volume to be rem- oved
  2. Type "select volume [drive letter(or drive number)], hit enter for example: "select volume G" or "select volume 5"
  3. type "remove letter [VOLUME LETTER]" 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]" , here replace the [volume letter] to any letter which you want to assign to the volume.

    CAUTION! I DO NOT KNOW WHETHER THIS WORKS IN WIN 8(OR WIN 8.1), but works well in win 7. I use this method to hide any volume.

RogUE

Posted 2014-01-21T15:02:58.307

Reputation: 2 431

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 

Knuckle-Dragger

Posted 2014-01-21T15:02:58.307

Reputation: 1 817

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.

Kamil

Posted 2014-01-21T15:02:58.307

Reputation: 2 524

Please expand upon this answer—link-only answers aren't particularly useful and can become invalid altogether if the linked content becomes unavailable. – bwDraco – 2014-12-26T19:26:49.203

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 – 2014-12-26T21:21:31.350

Sorry guys, I thought that single "diskpart" word could be an answer. I added more details. – Kamil – 2014-12-26T21:46:48.207

I didn't expected that improving post will cause downvotes :) – Kamil – 2014-12-26T21:49:54.413

diskpart CANNOT unmount volumes – Costin Gușă – 2015-05-10T21:58:29.007