Jump to content











Photo
- - - - -

How to get partitions path in command prompt?


  • Please log in to reply
68 replies to this topic

#26 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15044 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 03 January 2015 - 07:19 PM

I still haven't found the cmd command i had used, but i found a NirSoft program that is listing the partitions the way i want with the corresponding letters for them: http://nirsoft.net/u...etter_view.html

NO. :(

This is what you "want":
C: \Device\Harddisk0\Partition1
 
This is what that otherwise very nice Nirsoft tool (which is not command line) provides (as well as a number of other tools, including some of the mentioned ones):
C: \Device\HarddiskVolume1 (besides the info that the volume belongs to \\?\PhysicalDrive0)
 
They are NOT the same (though they all in all link to the same volume/device :)).
 
Here is a snippet (edited) of the output of dd --list:
 

rawwrite dd for windows version 0.5.
Written by John Newbigin <jn@it.swin.edu.au>
This program is covered by the GPL. See copying.txt for details
Win32 Available Volume Information
\\.\Volume{b0b284c3-8a33-11dd-8781-806d6172696f}\
link to \\?\Device\Harddisk0\Partition1
fixed media
Mounted on \\.\c:
...
 
NT Block Device Objects
...
\\?\Device\Harddisk0\Partition1
link to \\?\Device\HarddiskVolume1
...

 
Can you see it?

 

And here is a snippet of dmdiag -v:

 

...
---------- Drive Letter Usage, Drive Type ----------

C: = \Device\HarddiskVolume1 [Fixed]

...

---------- \Device\Harddisk0 ----------

\Device\Harddisk0\DP(1)0x7e00-0x4a85ad0400+2 (Device)
\Device\Harddisk0\DR0 (Device)
\Device\Harddisk0\Partition0 (SymbolicLink) -> \Device\Harddisk0\DR0
\Device\Harddisk0\Partition1 (SymbolicLink) -> \Device\HarddiskVolume1

...

 

 

 

:duff:

Wonko



#27 Peter80

Peter80

    Frequent Member

  • Advanced user
  • 115 posts

Posted 03 January 2015 - 08:37 PM

Yes, \Device\HarddiskVolume1 is not the same as \Device\Harddisk0\Partition1.
I missed that.



#28 erwan.l

erwan.l

    Platinum Member

  • Developer
  • 2785 posts
  • Location:Nantes - France
  •  
    France

Posted 03 January 2015 - 09:45 PM

Hi, note that vmount ( http://reboot.pro/topic/19622-vmount/ ) can also list partitions along with drive letters.

Regards,
Erwan

#29 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 04 January 2015 - 02:42 AM

I think I found a way to display all physical drives and the corresponding partitions.

The following script creates a *vbs file that uses the wmi to retrieve the desired information.

The *vbs will be run and deleted afterwards.

All credits go to Ruediger Roesler, who posted his extensive script here:

https://gallery.tech...of-all-2a738404

 

I simply shrinked and modified his script to get a minimum of info only. It can be enhanced widely.

Till now, settings of the vbs file display e.g. card readers but this can be changed by uncommenting two lines in the vbscript.

 

Wonko, what do you think?

Peter80, is it of use for you?

 

@Wonko,

Thanks for explaination. I'm not worried at all. As so often, you went behind my "language barriere" to get what I really tried to say (or to do). Thanks.

Attached Files



#30 Peter80

Peter80

    Frequent Member

  • Advanced user
  • 115 posts

Posted 04 January 2015 - 09:08 AM

Peter80, is it of use for you?

 

This is the output i am getting:

\\.\PHYSICALDRIVE0 (Hitachi HTS542516K9SA00 ATA Device) Index:0
 Logical Drives:4
 \Disk0\Partition0\  C:
 \Disk0\Partition1\  G:
 \Disk0\Partition2\  D: Local Disc
  E:

The path for E: partition is missing and also TrueCrypt shows G: partition as number 2, but it start the counting from C: as number 1 and it doesn't include zero in the order.

 



#31 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 04 January 2015 - 12:44 PM

@Peter80,

E: is your CD-Rom drive and should not be displayed (referring to Wonko).

I modified the VBScript to show fixed drives only.

 

But remember Wonkos explaination in post 27.

I suppose that WMI win32_diskdrive enumerates disks as standard vb arrays (index starts with 0).

Counting these starts with positive integers.

 

But at least modifiying the output in the way you need seems to be simple.

The attached script will give two different outputs in one line (just to compare):

Partition.DeviceID | \Disk<DiskDriveIndex+1>\Partition<PartitionIndex+1>  <LogicalDiskVolumeLetter>:   <LogicalDiskVolumeLabel>

I think your desired output should appear. Please try.

Attached Files



#32 Peter80

Peter80

    Frequent Member

  • Advanced user
  • 115 posts

Posted 04 January 2015 - 03:51 PM

I think your desired output should appear. Please try.

 

I got this output:

\\.\PHYSICALDRIVE0 (Hitachi HTS542516K9SA00 ATA Device) HDIndex:0 HDCount:1
 Logical Drives:4
 Disk #0, Partition #0 | \Disk1\Partition1  C:
 Disk #0, Partition #1 | \Disk1\Partition2  G:
 Disk #0, Partition #2 | \Disk1\Partition3  D:   Local Disc
  E:

Also, drive E: is a partition, not CD-ROM:

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     F                       DVD-ROM         0 B  No Media
  Volume 1     C                NTFS   Partition     15 GB  Healthy    System
* Volume 2     G                RAW    Partition   3416 MB  Healthy
  Volume 3     D   Local Disc   NTFS   Partition     62 GB  Healthy
  Volume 4     E                NTFS   Partition     67 GB  Healthy


#33 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 04 January 2015 - 05:37 PM

Sorry, I see.

But furthermore it seems I misunderstood the code structure of the vbs.

Please try the attached new version with more extensive output.

Main problem is to display all the desired results in a proper way.

But to go sure the original vbs is working correctly - would you please download it from the url below?

Check if drives, partitions and volumes are displayed correctly.

Open a command prompt and execute the original ShowDrives.vbs with: cscript //nologo showdrives.vbs.

 

Link:

https://gallery.tech...of-all-2a738404

 

My attached file is a vbs file.

Change file extension to vbs and follow the steps above.

 

Attached Files

  • Attached File  test.txt   2.5KB   292 downloads


#34 Peter80

Peter80

    Frequent Member

  • Advanced user
  • 115 posts

Posted 04 January 2015 - 07:15 PM

The output from the original ShowDrives.vbs seems to be with no errors:

+++++++ Hitachi HTS542516K9SA00 ATA Device (\\.\PHYSICALDRIVE0) ++++++++

Index:               0
Interface Type:      IDE
Status:              OK
Capacity:            149.048 GiB
To the decimal base: 160.039 GB
Bytes Per Sector:    512 Byte
Total Sectors:       312576705
Total Cylinders:     19457
Total Heads:         255
Total Tracks:        4961535
Sectors Per Track:   63
Tracks Per Cylinder: 255
Capabilities:        Random Access
                     Supports Writing
                     SMART Notification
Manufacturer:        (Standard disk drives)
Media Type:          Fixed hard disk media
Num Logical Drives:  4
Signature:           32FC1A2F

SCSI Bus:            0
SCSI Logical Unit:   0
SCSI TargetId:       0
SCSI Port:           2

    ---------------------- Disk #0, Partition #0 -----------------------

        Type:     Installable File System

        Capacity: 16,125.00 MiB

        4KAligned: True

        This is a primary partition.
        Computer can be booted from this partition.
        OS is using this active partition for boot.

        ~~~~~~~~~~~~~~~~~~~~~~~~ Logical Drives ~~~~~~~~~~~~~~~~~~~~~~~~

            C:
            Filesystem: NTFS
            Tot. Space: 16125 MiB
            Free Space: 1117.31 MiB


    ---------------------- Disk #0, Partition #1 -----------------------

        Type:     Installable File System

        Capacity: 3,416.00 MiB

        4KAligned: True

        This is a primary partition.

        ~~~~~~~~~~~~~~~~~~~~~~~~ Logical Drives ~~~~~~~~~~~~~~~~~~~~~~~~

            G:
            Filesystem: Not ready.


    ---------------------- Disk #0, Partition #2 -----------------------

        Type:     Extended w/Extended Int 13

        Capacity: 133,083.87 MiB

        4KAligned: False


        ~~~~~~~~~~~~~~~~~~~~~~~~ Logical Drives ~~~~~~~~~~~~~~~~~~~~~~~~

            D:          Local Disc
            Filesystem: NTFS
            Tot. Space: 64286 MiB
            Free Space: 537.05 MiB


            E:
            Filesystem: NTFS
            Tot. Space: 68793.99 MiB
            Free Space: 3176.52 MiB

But if i try to run the attached .vbs script i got this error:

Input Error: There is no script engine for file extension ".bat".

Edited by Peter80, 04 January 2015 - 07:16 PM.


#35 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 04 January 2015 - 07:23 PM

These are very good news.

 

Try my script.

- download

- change file extension to vbs

- execute by typing: cscript //nologo test.vbs



#36 Peter80

Peter80

    Frequent Member

  • Advanced user
  • 115 posts

Posted 04 January 2015 - 08:45 PM



- change file extension to vbs

 


Sorry, my mistake, i previously used .bat for extension.

 

This is the output i got now:   

\\.\PHYSICALDRIVE0 (Hitachi HTS542516K9SA00 ATA Device)
 Index:              0
 Media Type:         Fixed hard disk media
 Logical Drives:     4

 Disk #0, Partition #0
 Type:               Installable File System

 Logical Drives:
 VolumeLetter:       C:
 VolumeName:
 Filesystem:         NTFS


 Disk #0, Partition #1
 Type:               Installable File System

 Logical Drives:
 VolumeLetter:       G:
 VolumeName:
 Filesystem:         Not ready.


 Disk #0, Partition #2
 Type:               Extended w/Extended Int 13

 Logical Drives:
 VolumeLetter:       D:
 VolumeName:         Local Disc
 Filesystem:         NTFS

 VolumeLetter:       E:
 VolumeName:
 Filesystem:         NTFS


#37 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 04 January 2015 - 09:02 PM

Your output looks promising.

Please give me some time to modify the output properly.

What output style do you prefer?

Data (Device/PartitionID, VolumeLetter, VolumeName) in one Column or in one or two rows?

Do you need some more info to display?

 



#38 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 05 January 2015 - 01:55 AM

Okay Peter80, new vbs with (hopefully) optimised code.

Please report.

 

 

Attached Files



#39 Peter80

Peter80

    Frequent Member

  • Advanced user
  • 115 posts

Posted 05 January 2015 - 09:23 AM



Okay Peter80, new vbs with (hopefully) optimised code.

Please report.

I got error when running the script:

 

fz5eBZjl.jpg

 



Your output looks promising.

Please give me some time to modify the output properly.

What output style do you prefer?

Data (Device/PartitionID, VolumeLetter, VolumeName) in one Column or in one or two rows?

Do you need some more info to display?

Do the output as it more easy for you. I don't have special preferences.

This info will be enough.



#40 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 05 January 2015 - 09:43 AM

Post edited:

This is, because you double-cklicked it.

Lines 8+9 prevent the script from beeing executed outside the command prompt.

Open command prompt and type: cscript /nologo ZShowDrives.vbs



#41 Peter80

Peter80

    Frequent Member

  • Advanced user
  • 115 posts

Posted 05 January 2015 - 11:32 AM

I forget about cscript //nologo. This is the output i got:

E:\Desktop>cscript //nologo ZShowDrives.vbs


\\.\PHYSICALDRIVE0 (Hitachi HTS542516K9SA00 ATA Device)
    Disk #0, Partition #0 | (\Disk1\Partition1)  C:
    Disk #0, Partition #1 | (\Disk1\Partition2)  G:
    Disk #0, Partition #2 | (\Disk1\Partition3)  D:
    Disk #0, Partition #2 | (\Disk1\Partition3)  E:


#42 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 05 January 2015 - 04:15 PM

Not okay?

- LogicalDisk DeviceID C: is associated with the first partition of the first diskdrive

- LogicalDisk DeviceID G: is associated with the second partition of the first diskdrive

- LogicalDisk DeviceID's D: and E: are associated with the third partition of the first diskdrive,

  which is in fact ONE extended partition containing TWO logical disks

  (Wonko and/or other experts, correct me if I'm wrong).



#43 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15044 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 05 January 2015 - 07:59 PM

A side note about disks/partitions numbering.

Windows NT numbers disks starting at 0 (First disk is 0) and partitions as 0 (First partition on any disk is 0) BUT ONLY in SOME paths/notations, while disks ALWAYS start from 0, partitions in some notations start from 1, the first partition on first disk, i.e. \\.\Physicaldrive0 is:
Disk #0, Partition #0
\\?\Device\Harddisk0\Partition1
\\?\Device\HarddiskVolume1
multi(0)disk(0)rdisk(0)partition(1)

The partition entries in the MBR have been traditionally numbered base 0, i.e. first partition entry is partition entry #0.

Linux numbers disks starting from 0 and partitions starting from 1.

GRUB (the "real" thing, now senselessly called GRUB Legacy") and grub4dos use partition entries to number partitions, thus first partition on a disk is "the partition which addresses are in partition entry #0).

GRUB2 (the new thingy now senselessly called GRUB and creating more confusion than needed) adopts for compatibility with Linux the partition numbering from 1, but uses additionally a new rather unuseful/unneededly complex naming, depending on the type of the partition.

Some nice mismatching may additionally happen when (IF) the order of partition entries in the MBR (and possibly even in the EMBR chain) is not the same as the disk layout.

@Zharif
See if the little batch attach would do ;).

:duff:
Wonko

Attached Files



#44 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 05 January 2015 - 09:51 PM

 

Some nice mismatching may additionally happen when (IF) the order of partition entries in the MBR (and possibly even in the EMBR chain) is not the same as the disk layout.

 

 

This exactly is the reason for my delay in posting.

I surely know, this story is old for you, but I just investigated drive/partition info since one day only.

I connected an external USB-Drive to my PC and formatted it with a similar layout as Peter80 (MBR, two primary ones; order <N: O:>and one extended as a container for two partitions; order <P and Q:>).

By changing driveletters, the interesting thing is that mismatch occurs on the extended partition only.

 

- Changing the drive letters of the  two first partitions (e.g. O: N:) results in the same output for our scripts.

  It seems that alphabetical order is ignored - DeviceID doesn't change.

- Changing the drive letters inside the container (e.g. Q: P:) results in a change of the DeviceID.

  It should not. In this case the alphabetical order of the driveletter seems to be relevant.

- On my two fixed harddrives (GPT each with two partitions) no mismatch occurs by changing the driveletters.

- Till now I didn't test results if you remove a driveletter.

 

Normally, it wouldn't be a problem to simply count the logical drives found in the container.

But using wmi on a HD using  the MBR partition table, the order for logical drives inside the container seems to change and will lead to false positive results.

 

 

Disk #0, Partition #0
\\?\Device\Harddisk0\Partition1
\\?\Device\HarddiskVolume1
multi(0)disk(0)rdisk(0)partition(1)

 

 

In regard to extended partitions, the last one seems to be the most reliable one cause it seems to be the only one providing info about an existing container partition.?

 

So, by by WMI???

I know that api calls such as DosDevices(W), DeviceIO functions will access the harddrive/partition info.

At least I wonder how external software, such as partitioning software access the drives correctly.

Using api only or wmi? In regard of the observed wmi-behaviour, the latter seems to be a bad choice.

 

Thanks for explaination and your script.

I would prefer to use "OR", rather than "Z". :-)

I didn't know that the assoc statement could be directly put into commandline (should have read some more about the wmic syntax).

 

@Peter80

Use Wonkos' script.

But if you like, I could wrap the vbs into a batch and change the output in a similar/same way as Wonko did.

Your choice...



#45 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 05 January 2015 - 10:57 PM

Wonko,

I did a closer look at your script

 

 

 

::- Find Hard disk partition, NT device, drive letter (IF any) corresponding
::_ Handcrafted in order to comply with Occam's Razor and slightly obfuscated
::_ for No reason but for the fun of doing it
::_ (deobfuscationg it would be a good exercise for a batch writer)
::_ by jaclaz on January 5, 2015

;IF %1.==/?. CALL :-

:_
;IF %2.==. FOR /F "tokens=*" %%? IN ('Type %~dpnx0^|FIND "::-"^|FIND  /V "FIND"') DO ECHO %%?&CALL :_ %%?&GOTO :EOF

 

 

 

So cool, very nice. Lesson completed.

I still have to investigate your "SET /A $=" statement and the carets in the For /F loops.

 

Notes:

I interpret your "comments" as a personal request.

But Ockham? I was in the need to read some of his work in regard of medical scientific theory.

Anyway, I like your comparison.

 

Zharif



#46 Peter80

Peter80

    Frequent Member

  • Advanced user
  • 115 posts

Posted 06 January 2015 - 08:50 AM

@Peter80

Use Wonkos' script.

But if you like, I could wrap the vbs into a batch and change the output in a similar/same way as Wonko did.

Your choice...

 

It doesn't seem to detect all partitions, partition D: is missing:

E:\Desktop\zdrivesOR>zdrivesOR.cmd
::- Find Hard disk partition, NT device, drive letter (IF any) corresponding
Disk#0, Partition #0 -> \HardDisk0\Partition1 -> C:
Disk#0, Partition #1 -> \HardDisk0\Partition2 -> G:
Disk#0, Partition #2 -> \HardDisk0\Partition3 -> E:


#47 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 06 January 2015 - 09:30 AM

Yes, I see.

While trying to "deobfuscate" Wonkos script I found out the error.

His script stores the DeviceID's as environmental variables.

Although you have at least four partitions, only three DeviceID's are written to the environment (two primaries, and one extended).

The loop to get the associated driveletters works as expected, but cause wmic finds four driveletters one will be overwritten.

 

This is Wonkos script. It's his turn to correct this. I still didn't completed "deobfuscation".

Furthermore real life (work) was calling me since yesterday. My spare time becomes limited.



#48 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15044 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 06 January 2015 - 11:17 AM

Well, it was just some fun. :)

 

the "clear" batch is not really a batch, it is just a bunch of lines, three for loops, only to show how for simple things a simple batch can compete with the much more complex .vbs script (winning hands down ;) when it comes to go through Ockham's Razor, or more plainly using the KISS principle).

 

Find it attached in a simple, clear form. 

 

The issue here is that - as often happens - there is the usual confusion between partitions, volumes and the "whatever" that gets a drive letter assigned in Windows NT, see also:

http://cquirke.mvps....x/partition.htm

 

The WMI path Win32_DiskPartition lists partitions (and not volumes/drives).

"starting" with it means to have "false" results if an extended partition is involved, as what is found and expressed as:

Disk #m, Partition #n

is the disk # and the partition entry slot # in the MBR, and the extended partition (that may contain one or a zillion volumes) occupies a slot, independently from the number of volumes in it, and the "trick" of creating a \Harddiskm\partition(n+1) with that data fails miserably. :(

ON th eother hand, a volume that has not a drive letter assigned is not (according to the good MS guys and WMI) a logicalvolume, so it is "transparent" to WMI Path Win32_LogicalDiskToPartition or to Win32_LogicalDisk.

 

As hinted before, and AFAIK, WMI - at least in XP - simply misses some needed info, and there is the need to use another approach (or a mixed one making use of other built in programs, like Diskpart - which has it's own "quirks" and/or mountvol and/or fsutil, etc.).

 

:duff:

Wonko

 

 

 

 

Attached Files



#49 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 06 January 2015 - 12:46 PM


The WMI path Win32_DiskPartition lists partitions (and not volumes/drives).

My fault - I know. Inaccurate phrasing, so sorry.

I got my info from your provided link and from here (german):

http://windows.micro...-logical-drives

 

Tell me, is it correct to denote one extended partition as one "container partition" for volumes (requirement: driveletter assigned)?

 

And in regard to an extended partition that contains e.g. two volumes -

what about this output/writing:

    Disk #0, Partition #0 | (\Disk0\Partition1)  C:
    Disk #0, Partition #1 | (\Disk0\Partition2)  G:
    Disk #0, Partition #2 | (\Disk0\Partition3\Volume1)  D:
    Disk #0, Partition #2 | (\Disk0\Partition3\Volume2)  E:

 

 

About WMI and XP:

I tested the vbs on XP, Vista and Win8.1.

Aliases' diskdrive, logicaldisk and partition are available as well as their associated entries for DeviceID, Caption, Index and DiskIndex. As far as I understood, nothing more is needed here.

But anayway, my posted issue about alternating DiskDrive.DeviceID's will still persist.

 



#50 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 06 January 2015 - 01:44 PM

Here is the new script.

Back to the roots - it's a cmd file and must be executed inside the command prompt.

- open command prompt

- type: ZShowDrives.cmd

 

Creates the vbs, runs and deletes it.

Output is sorted (I put everything in a collection object) in three notations.

It (should) look like this:

Disk #0, Partition #0 --> \Disk0\Partition1 --> \Disk0\Partition1\Volume1  C:
Disk #0, Partition #1 --> \Disk0\Partition2 --> \Disk0\Partition2\Volume1  D:
Disk #0, Partition #2 --> \Disk0\Partition3 --> \Disk0\Partition3\Volume1  E:
Disk #0, Partition #2 --> \Disk0\Partition3 --> \Disk0\Partition3\Volume2  G:

 

Peter80, please report.

Attached Files






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users