Jump to content

Recommended Posts

Posted

Hi all,

Trying to script unmounting and then remounting a drive. I've like to use WMI and have been digging around there but haven't found anything yet. Anyone have any experience with this?

TIA!

Jerry

Posted

Once again - I'm trying to dismount and mount a physical hard drive.

Specifically, when rebuilding a a machine with a second hard drive PHYSICALLY attached - either by IDE, SATA, USB, or Fire Wire - I want to make that drive unavailable during a specific routine and then make it available again.

I don't understand how SUBST would apply, but I'm slow today!

Posted

I should have been clearer. I meant a physically connected drive - IDE, SATA, USB.

Ahhh, you did say drive and not share... I should have caught that.

I was wondering about your desire to use WMI because I knew that you knew about Net Use. Maybe a WMI guru will stop by soon.

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted (edited)

Sorry that I miss understand you, English is my second language :)

I know you are looking for WMI script, but in case that you don't found any you can use diskpart (assing, remove) switches as a work around.

This is a nice udf from dem3tre

Microsoft TechNet

Thanks Danny35d. The UDF is really nice, but unfortunately not only does it not have anything for dismounting a drive, I've tried diskpart and for whatever reason it's not working, which is why I thought WMI might be better suited.

Actually, it occurs to me that the drive(s) in question are almost always in an IDE or SATA drive bay on a laptop or connected via a USB or FireWire to IDE/SATA adapter, and these devices always appear in the "Safely Remove Hardware" list when you double click the (PCMCIA/Arrow) icon in the system tray. It also occurs to me that when you do stop (disable? dismount) one of these drives, the only way (I'm aware of) to get the drive to be available again is to unplug and then replug it.

Thanks again all for your help.

Edited by JerryD
Posted (edited)

It also occurs to me that when you do stop (disable? dismount) one of these drives, the only way (I'm aware of) to get the drive to be available again is to unplug and then replug it.

I was about to recommend Devcon, but you are right. You will need to unplug and then replug it. I don't know how to use diskpart_UDF, but you can do this steps manually and then try to come up with the script.

1) Attach usb drive and open windows explorer "MY Computer" the window where you can see all the drives letters:

2) open command prompt CMD.

3) type diskpart

4) type list volume

5) type select volume 3 (volume 3 is the one which has the usb drive letter that you want to unmount)

6) type remove (Once return successfully removed you will see on the windows explorer the drive letter is gone)

7) type assing (Once return successfully assigned You will see on the windows explorer the drive letter reappear)

Hope this help.

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Posted

I was about to recommend Devcon, but you are right. You will need to unplug and then replug it. I don't know how to use diskpart_UDF, but you can do this steps manually and then try to come up with the script.

1) Attach usb drive and open windows explorer "MY Computer" the window where you can see all the drives letters:

2) open command prompt CMD.

3) type diskpart

4) type list volume

5) type select volume 3 (volume 3 is the one which has the usb drive letter that you want to unmount)

6) type remove (Once return successfully removed you will see on the windows explorer the drive letter is gone)

7) type assing (Once return successfully assigned You will see on the windows explorer the drive letter reappear)

Hope this help.

You lost me at step 7 - what's "assing"?
Posted

Another option is using Mountvol.exe.

Like Joon mention is another option.

Trying to script unmounting and then remounting a drive

You first post said you want to unmount (remove) and then after you done doing some staff remount (assign).

Basically diskpart remove switch is to unmount or remove drive letter from the select volume and assign switch is to mount or assing drive letter to the selected volumen.

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Posted (edited)

Joon - THANKS! MountVol is perfect! It will be a bit tricky to grab the volume name, but dem3tre's excellent DiskPart UDF should be really helpful in setting up some functions for MountVol.

Danny35d - got it now. Thanks for your help with diskpart's syntax. OH YEA - RoboCopyGUI is very cool too!

Edited by JerryD
Posted

Your welcome, the only issue I can see with Mountvol.exe, I could be wrong. I think you will be able to unmound a drive, but won't be able to mounted back. You may need to unplug the usb and plug it back.

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Posted

Your welcome, the only issue I can see with Mountvol.exe, I could be wrong. I think you will be able to unmound a drive, but won't be able to mounted back. You may need to unplug the usb and plug it back.

Well I'm happy to say you're wrong! But that's COOL!! The only thing is grabbing the right drive, but that shouldn't be too hard.

With the drive connected, when you run MountVol /L, the second hard drive is listed like this:

\\?\Volume{a4f956a1-fea4-11d9-88a3-806d6172696f}\
    D:\

Then when you run MountVol D:\ /D, the drive is listed like this:

\\?\Volume{a4f956a1-fea4-11d9-88a3-806d6172696f}\
    *** NO MOUNT POINTS ***

Then running MountVol D:\ \\?\Volume{a4f956a1-fea4-11d9-88a3-806d6172696f}\ remounts the drive.

This all happens just about instantly!

Thanks again to all for your help.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...