Count empty drive letters

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Count empty drive letters

#1 Post by sambul35 » 18 Jan 2012 10:22

Hello guys, great forum! :D

Diskpart command can Detail Disk #, printing on screen list of its volumes with Volume # and DriveLetter for each. Some volumes aren't mounted, so don't have DriveLetter. What's the best way to list and save unmounted volume numbers for a selected disk to variables?

Also, is it possible via a batch to unmount a volume on a multivolume disk without removing its drive letter - this way it can be automounted next time. Since its Vdisk (VHD), Fsutil can't dismount its volumes, and Mountvol or Diskpart remove drive letter, so next time the VHD is attached, that volume is not automounted.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Count empty drive letters

#2 Post by Ed Dyreen » 18 Jan 2012 10:45

'
Aaii, the best way ?? I have no idea, I know at least three totally different ways, I leave "best" up you to..
Personally I like this way a lot, you won't be able to run the code as is, but if your skills are adequate, you should get the idea:

Code: Select all

:§Drive.mounted ()
::
:: last updated       : 20/11/2011
:: language dependent : no
:: languages          : N/A
::
::OUTPUT:
:: $drives.mounted,[.FLP¦.HD¦.CD¦.NET¦.RMV], $drives.unmounted
::
:: NFO ( uses registry to get mounted drive types
::
::   G . E . N . E . R . I . C . _ . F . L . O . P . P . Y . _ . D . R . I . V . E       Floppy
::   470045004e0045005200490043005f0046004c004f005000500059005f00440052004900560045
::   C . d . R . o . m                            CD
::   4300640052006f006d
::
::    5C003F00                              HD
::
::    Networked drives are NOT listed under HKLM\SYSTEM\MountedDevices !
:: )

Code: Select all

for /f "skip=16 tokens=1 delims=\ " %%? in ('mountVol.EXE') do 

Code: Select all

for /f "tokens=2,4 delims=\    " %%a in ('reg query HKLM\SYSTEM\MountedDevices') do

Code: Select all

   :: $drives.mounted.NET
   :: (
      for /f "skip=6 tokens=1,2" %%a in (

         'net use'

      ) do    if /i ["%%~a"] equ ["OK"] (
         ::
         set     "$drives.mounted=!$drives.mounted!, %%~b"
         set "$drives.mounted.NET=!$drives.mounted.NET!, %%~b"
         set "$drives.mounted.RMV=!$drives.mounted.RMV!, %%~b"
         %@echo_% %%~b
      )
   :: )
I know, it's incomplete, but I really don't want to hijack this wonderful forum.
http://www.dostips.com/forum/viewtopic.php?f=3&t=1893
Demounting is done with mountvol or net use /delete for networked drives.
Also, is it possible via a batch to unmount a volume on a multivolume disk without removing its drive letter
I think you are confused, mounting means assigning a drive letter, if none assigned it is unmounted :idea:

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Count empty drive letters

#3 Post by sambul35 » 18 Jan 2012 11:15

Thanks,

Its not exactly what I asked for (I wanted to limit the list to a subset of unmounted volumes on a selected disk), but...may be next time. :D

As to been consufed, not exactly. The problem is, when a Vdisk is unmounted, its volumes retain drive letters, and can be automounted next time the vdisk is attached. So the question was, how to dismount a single volume on a multivolume attached vdisk (or a regular disk) via batch without affecting its ability to automount next time?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Count empty drive letters

#4 Post by Ed Dyreen » 18 Jan 2012 11:51

'
Vdisk does that stand for Virtual disk ? Like a virtual floppy disk ?
In that case it would need a driver right ?
So disabling the driver would unmount it...

I'm at the end of my latin, I'm afraid I can't help u :|

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Count empty drive letters

#5 Post by sambul35 » 18 Jan 2012 12:20

That's fine. May be you can suggest another issue:

When a user is prompted for input with Set /p to enter file name, how to type a suggested file name on screen that the user can directly edit by typing?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Count empty drive letters

#6 Post by Squashman » 18 Jan 2012 16:48

sambul35 wrote:That's fine. May be you can suggest another issue:

When a user is prompted for input with Set /p to enter file name, how to type a suggested file name on screen that the user can directly edit by typing?

I don't think it can be done in pure batch but I could be wrong. But here is a third party solution for you.
http://www.westmesatech.com/editv.html

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Count empty drive letters

#7 Post by sambul35 » 18 Jan 2012 17:07

Thanks, that will do. :D

I'm kind of new to batch files, so may ask stupid questions. Once I debugged the batch, how I can convert it to .exe file (possibly encrypted), so that it can be executed in Win7 32/64-bit Command Prompt, but its content would be harder to read?
Last edited by sambul35 on 18 Jan 2012 17:47, edited 1 time in total.

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Count empty drive letters

#8 Post by sambul35 » 21 Jan 2012 14:05

Sorry guys for repeating my question.

Can someone suggest a batch to list unmounted volume numbers or GUIDs for a given drive (disk 3 or GUID...) with Diskpart or WMIC? I mean, not a sample that lists mounted volumes without linking them to physical disks, but the code as requested? :)

Post Reply