Jump to content

How to Return the value "Simple Volume Size in MB"?


 Share

Recommended Posts

How can I get the "Simple Volume Size in MB" for and Disk # I select. The value I am talking about is seen when you open Disk Management, select your disk, right-click >  "New Simple Volume...".

I would like to enter the desired disk number via an input box. Then return this "Simple Volume Size in MB" value. I don't want the DISKPART size as that is rounded (see picture). I already have script that extracts that, but I found out I need even more precise values. Any ideas of how to get this information? Been reading up on _WinAPI_GetDiskFreeSpaceEx() and _WinAPI_GetDriveNumber(), but I am not seeing how I could use these to get my results. One thing to note is these drives won't have drive letters associated with them at any point, so drive letter searching is useless.

 

2016-11-10.jpg

Edited by donhorn20
upload picture
Link to comment
Share on other sites

  • Moderators

Your 4095.88 is simply 4194174 / 1024. You could do that through some simple math.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

If your disk is NTFS or FAT or similar, you can use my BuildPartitionTable UDF (link in my sig) to get disk/partition sizes exact to the byte.

Link to comment
Share on other sites

13 hours ago, JLogan3o13 said:

Your 4095.88 is simply 4194174 / 1024. You could do that through some simple math.

Thanks JLogan3o13 for the reply. I do understand that simple math will get me that value. Maybe I wasn't clear enough in my original post. How can I extract the number 4194174 or 4095.88 when only providing the disk number to my interface?

Scenario, a person enters the Disk number into an input field. I want to get the results of the disk 2, in this case the returned value could be 4194174 or if there is a way I can read from the disk management "Disk 2" section take the 4095.88 value, then I can do the math in the background to retain my results.

Any ideas where I can find either one of these stored values, and how to extract them?

Link to comment
Share on other sites

  • Moderators

You could pull this information from WMI (search the forum for scriptomatic if you are unfamiliar). Something like this would get the information you're after:

Const $wbemFlagReturnImmediately = 0x10
Const $wbemFlagForwardOnly = 0x20
Local $oWMI, $oDrives, $sID, $sName, $iSizeinBytes

$oWMI = ObjGet("winmgmts:\\.\root\cimv2")
    If IsObj($oWMI) Then
        $oDrives = $oWMI.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
            If IsObj($oDrives) Then
                For $sDrive In $oDrives
                    If $sDrive.Index = 0 Then
                        $sID = $sDrive.DeviceID
                        $sName = $sDrive.Caption
                        $iSizeinBytes = $sDrive.Size
                        ConsoleWrite("ID: " & $sID & @CRLF & "Drive Index: " & "Drive Name: " & $sName & @CRLF & "Drive Size in Bytes: " & $iSizeinBytes & @CRLF)
                    EndIf
                Next
            Else
                ConsoleWriteError("Unable to pull Disk Info" & @CRLF)
            EndIf
    Else
        ConsoleWriteError("Unable to connect to WMI" & @CRLF)
    EndIf

You should be able to easily adapt this to a GUI, and change the If $sDrive.Index = 0 statement to something like If $sDrive.Index = GuiCtrlRead(<input field on your GUI>)

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Well I looked into Scriptomatic and tried out the code you provided. It does return the drive size in bytes, but it still is the incorrect value being captured. I even tried the Win32_Volume to see if it would produce different results. But I still get the same output. Check out what I mean.

Scriptomatic returns size in Bytes = 4398040765440

I convert that to MB 4398040765440 / 1048576 = 4194298.520507813 MB

Notice this isn't even close to what the Windows Properties shows for this volume. As a matter of fact you get different results depending on how you look at the volume. Ultimately I need to find a way to get 4095.88 GB or 4194174 MB based off of disk # selected. Right now I am not seeing an easy way of extracting that data. Have you guys seen this type of discrepancy before? Here is the code with a simple input box if you want to see your own results.

 

#include <ButtonConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <WindowsConstants.au3>


Opt("GUICoordMode", 1)
Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled
Opt("GUICloseOnEsc", 1) ;Send $GUI_EVENT_CLOSE message when ESC is pressed


$GUI = GUICreate("", 175, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$Label_DiskStart = GUICtrlCreateLabel("Disk #", 10, 20, 50, 17) ;Disk Start Label
GUICtrlSetState(-1, $GUI_SHOW) ;Label
$Input_DiskStart = GUICtrlCreateInput("", 60, 17, 65, 21, $ES_NUMBER) ;DiskStart Input / Numbers Only
GUICtrlSetState(-1, $GUI_SHOW) ;Label
$Button_Execute1 = GUICtrlCreateButton("Execute", 10, 60, 50, 25) ;Execute Button on left
GUICtrlSetOnEvent(-1, "_Button1") ;Execute button calls the _Button function
$Button_Close = GUICtrlCreateButton("Exit", 100, 60, 50, 25) ;Close Button
GUICtrlSetOnEvent(-1, "_Exit") ;Close button calls _Exit function
GUISetState()


While 1

WEnd


Func _Button1()
Const $wbemFlagReturnImmediately = 0x10
Const $wbemFlagForwardOnly = 0x20
Local $oWMI, $oDrives, $sID, $sName, $iSizeinBytes, $Output

$oWMI = ObjGet("winmgmts:\\.\root\cimv2")

    If IsObj($oWMI) Then
        $oDrives = $oWMI.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
            If IsObj($oDrives) Then
                For $sDrive In $oDrives
                    If $sDrive.Index = GUICtrlRead($Input_DiskStart) Then
                        $sID = $sDrive.DeviceID
                        $sName = $sDrive.Caption
                        $iSizeinBytes = $sDrive.Size
                        $sIndex = $sDrive.Index
                        ConsoleWriteLine("ID: " & $sID & @CRLF & "Drive Index: " & $sIndex & @CRLF & "Drive Name: " & $sName & @CRLF & "Drive Size in Bytes: " & $iSizeinBytes & @CRLF)
                    EndIf
                Next
            Else
                ConsoleWriteLine("Unable to pull Disk Info" & @CRLF)
            EndIf
    Else
        ConsoleWriteLine("Unable to connect to WMI" & @CRLF)
    EndIf
EndFunc

Func consolewriteline($text)
    ConsoleWrite($text & @CRLF)
    MsgBox(64,"",$text & @CRLF)
EndFunc   ;==>consolewriteline


Func _Exit() ;Exits Application
    Exit
EndFunc   ;==>_Exit

 

2016-11-11 17.jpg

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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