Hello Erwan,
thank you so much for this nice tool!
The vmount remove option is very useful: up to now the only way I had found was to assign C: letter with diskpart.
I've started testing the many functions you implemented and many of them are working greatly at the first shot.
I wish I had found vmount long time ago!
I have already plenty of questions and I read all this thread briefly to better understand all the options of each command, but I already found something worth to ask you.
I'm trying to re-write a batch script to allow me to detach a vhd either via its path, or its disc number (which is trivial with vmount) but also via the mounted volume letter. I couldn't find a tool that does this natively unfortunately so I created my own script and added it to the registry HKEY_CLASSES_ROOT\Drive\shell\VhdDetach and finally I can avoid wasting the time to find any vhd file to be able to detach it.
In the first version I made, before knowing of vmount, used "vol" "mbrwiz3" and "diskpart". Too cumbersome even if it's working correctly.
I'm trying to simplify things by using only vmount itself but I'm afraid I'm missing something or doing something wrong.
Here the simple algorithm I thought about in principle (the argument given to the script: VhdPath or DiskNumber or VolLetter):
- - If arg extension is "vhd(x)" check if file exist and launch vmount
- - If arg is a DiskNumber check if the Disk is a "Virtual_Disk" and launch vmount
- - If arg is a VolLetter check if Volume is a "Virtual_Disk", get the DiskNumber and launch vmount
The first two options are pretty easy to achieve but the third one seems cumbersome. Here what I did so far:
::GET DRIVE NUMBER AND VOL LABEL FROM LETTER (OR EVENTUALLY GET LETTER AND DRIVE FROM VOL LABEL)
for /f "tokens=1-5 delims= " %%1 in ('vmount partitions ^| find "%DLTR%"') do SET VNME=%%2& SET DRIVE=%%4
::REMOVE SQUARE BRACKETS
SET VNME=%VNME:[=%
SET VNME=%VNME:]=%
::EXTRACT DRIVE NUMBER FROM STRING
SET DRIVE=%DRIVE:\device\harddisk=%
for /f "tokens=1 delims=\" %%1 in ('echo %DRIVE%') do SET DRIVE=%%1
I tried to use filters but if I launch vmount partitions C: or vmount partitions "C:" I get no output at all and the find command is unreliable for vmount disks command EDIT: I just read that the filters are only for the Device column
::CHECK IF DISK IS VIRTUAL AND IF IT'S NOT EXITS
for /f "tokens=1,2,3 delims= " %%1 in ('vmount disks ^| find "%DRIVE%"') do SET DSKNR=%%1& SET PID=%%3
IF ["%PID%"] NEQ ["Virtual_Disk"] EXIT
This seems to work but it's risky even if I add a tab to the find argument. I often use to grep or find strings adding leading and trailing spaces to avoid catching useless rows from a command, but unfortunately here we have no leading tab (or space) to add. Please have a look at my current output (I reduced its rows to simplify):
DiskNr SN ProductId Size Type Removable
0 [E39479FC] 001-1RG174 1907729MB SATA NON-REMOVABLE
2 [69BB67D8] mSATAM1_064 61057MB SATA NON-REMOVABLE
4 [0F679E55] Virtual_Disk 51200MB UNKNOWN NON-REMOVABLE
7 [D625F04F] RAMDISK 21798MB UNKNOWN NON-REMOVABLE
9 [C56FF557] Virtual_Disk 61057MB UNKNOWN NON-REMOVABLE
10 [A0C4A262] Virtual_Disk 61057MB UNKNOWN NON-REMOVABLE
If I use 9 or 10 for %DRIVE%, I get in both cases the correct output, while if I use 4+tab I have three possible results and I would need to parse every single row. This could be simplified by adding a tab before each row. But another great improvement would be to add a column with the disk number in the partitions' output.
Is there a simpler way to check from a volume letter or a label if the volume is a VHD? Am I making simple things too complex maybe ?
--------------------------
Besides this first use, I need also to get the path to the mounted vhd files. I use bginfo to write on screen at boot which is the file I booted from (as I use a common vhd base system for many PCs and then boot from several different diff vhds, depending on each computer or use).
For this purpose I use diskpart but it's not clean and a bit too complex in my opinion and I would love to re-write my script using only vmount.
The simplest algorithm I can imagine could be (argument given to the script: VolLetter or MontPoint) the following:
- - vmount partitions to get the #Disk from the Volume Letter (or eventually mount point)
- - vmount getstoragedependencyinfo to get DependentVolumeRelativePath and HostVolumeName
- - Assemble the previous results accordingly
With diskpart it's quite the same for the vhd's you boot from, but for all the others you get directly the complete vhd path. I don't know why this difference , there must be a reason that only Wonko, Steve, Wimb and other experts like you might figure out...
As you can see the leading spaces can greatly help reducing the batch file complexity as find "Disk" might catch both "Disk" and "VDisk" " Disk " is different than " VDisk "
C:\Users\Admin>echo list vdisk | diskpart
DISKPART>
VDisk ### Disk ### State Type File
--------- -------- -------------------- --------- ----
VDisk 0 Disk 10 Attached not open Expandable R:\W7U64_2nd_Drivers.vhd
VDisk 1 Disk 9 Attached not open Expandable R:\W7U64_1st_Clean.vhd
VDisk 2 Disk 4 Attached not open Fixed \Device\HarddiskVolume1\NuOS_diff.vhd
Is there a way to get from vmount getstoragedependencyinfo the "DependentVolumeRelativePath:" without passing through vmount volumes command?
vmount volumes | find "HostVolumeName's UUID"
That's all for now.
Again thank you for all the great work you've done so far and for all the improvements to come!
Virgus.
PS If you ever come to Paris please drop me a line, I would pleased to offer you a beer or lunch/dinner somewhere!
PPS I tried to add as many emoticons I could to honor Wonko's best traditions
Edited by virgus, 10 May 2020 - 02:57 PM.