Mount and dismount hard drive through a script/software [duplicate]

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!


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.

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.


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