HDD size

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Locked
Message
Author
MauricioDeAbreu
Posts: 38
Joined: 12 Dec 2021 06:45

HDD size

#1 Post by MauricioDeAbreu » 25 Dec 2021 14:08

Happy Christmas friends.

My question is regarding the actual size of the Hard Drive, and I say actual size to refer to the total size of the drive.

I am aware that with this line I can know the size of the hard disk

WMIC DiskDrive WHERE "DeviceID='\\\\.\\PHYSICALDRIVE0'" GET Size

But I wonder if this same code will give the real size of the hard disk even though one of its partitions is NOT active.

The fact is that, in my work there are laptops to which a 320GB image is cloned on a 500GB disk, and in order not to go around so many times to find out the exact size of the disk, and do it all from the same batch, I wanted to know if this is the correct way to get the size or there is a different way to get the correct size.

First of all, thanks for the help you can give me.

I apologize for my English, I use a translator.

aGerman
Expert
Posts: 4433
Joined: 22 Jan 2010 18:01
Location: Germany

Re: HDD size

#2 Post by aGerman » 27 Dec 2021 07:23

I don't know. However, since DiskDrive targets the physical drive, I would not expect that partitions affect the output.

Steffen

penpen
Expert
Posts: 1960
Joined: 23 Jun 2013 06:15
Location: Germany

Re: HDD size

#3 Post by penpen » 27 Dec 2021 08:35

I also don't know that and would expect it to work lke aGerman assumed; but you might test that for yourself, since you already seem to have such a setup (maybe you could get the information of all hdds remotely and check of one differs too muc; my partitions don't sum up to the disk size, which probably is caused by some sort of 'security distance' between the partitions):

Code: Select all

wmic partition get name,size
wmic diskDrive get name,size
Please let us know the answer to that :D .


penpen

MauricioDeAbreu
Posts: 38
Joined: 12 Dec 2021 06:45

Re: HDD size

#4 Post by MauricioDeAbreu » 27 Dec 2021 11:49

aGerman y penpen, thank you very much for answering
aGerman wrote:
27 Dec 2021 07:23
I don't know. However, since DiskDrive targets the physical drive, I would not expect that partitions affect the output.

Steffen
I agree with you, but before the doubt I had to ask.

i
penpen wrote:
27 Dec 2021 08:35
I also don't know that and would expect it to work lke aGerman assumed; but you might test that for yourself, since you already seem to have such a setup (maybe you could get the information of all hdds remotely and check of one differs too muc; my partitions don't sum up to the disk size, which probably is caused by some sort of 'security distance' between the partitions):

Code: Select all

wmic partition get name,size
wmic diskDrive get name,size
Please let us know the answer to that :D .

penpen
This line used it when I began to create the Batch: “wmic diskDrive get size”, Since I am interested in assigning the size of the HDD to a variable to check.

But, when executing the Batch from a pendrive, I showed me the size of the pendrive and not the hard drive, so change to this code: Wmic DiskDrive Where "DeviceID='\\\\.\\PhysicalDrive0'" Get Size.

The problem is that I could not try the batch in the laptops whose 500GB HDD are cloned with 320GB image.

So we'll have to wait a few days (since we're on vacation) to be able to determine if the command brings the actual size.

Grateful as usual for the help they give me, and I promise that I will inform the results.

Note: I apologize for my English, use translator.

Compo
Posts: 582
Joined: 21 Mar 2014 08:50

Re: HDD size

#5 Post by Compo » 27 Dec 2021 16:33

The diskdrive size is the size reported for the drive, and its contained partitions have no bearing on it.

You could find out with a 'quick' command in the prompt…

This should output your disks, their sizes, then the partitions with their sizes too:

Code: Select all

For /F "EOL=_ Tokens=1,* Delims==" %G In ('((Echo DiskDrive Get Name^, Size /Value ^& Echo DiskDrive Assoc:List /ResultClass:Win32_DiskPartition^) 2^>NUL ^| %SystemRoot%\System32\wbem\WMIC.exe^) ^| %SystemRoot%\System32\findstr.exe /R "^Name= ^Size="') Do @Echo %H
Based upon your last post, if you want to save the size of the Operating System disk to a variable, using a batch file, then the following method should do that. The last line is included just to show you the variablename and value, you could of course use %DiriveSize%, for your comparison.

Code: Select all

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Set "DriveSize="
For /F "Tokens=2 Delims=#," %%G in ('%SystemRoot%\System32\wbem\WMIC.exe
 LogicalDisk Where "DeviceID='%SystemDrive%'"
 Assoc /ResultClass:Win32_DiskPartition 2^>NUL'
) Do For /F "EOL=S" %%H In ('%SystemRoot%\System32\wbem\WMIC.exe DiskDrive Where
 "Index='%%G'" Get Size 2^>NUL') Do For %%I In (%%H) Do Set "DriveSize=%%I"
(Set DriveSize) 2>NUL
And to just see its size directly in a Command Prompt window, you could use this:

Code: Select all

For /F "Tokens=2 Delims=#," %G in ('%SystemRoot%\System32\wbem\WMIC.exe LogicalDisk Where "DeviceID='%SystemDrive%'" Assoc /ResultClass:Win32_DiskPartition 2^>NUL') Do @%SystemRoot%\System32\wbem\WMIC.exe DiskDrive Where "Index='%G'" Get Size /Value

MauricioDeAbreu
Posts: 38
Joined: 12 Dec 2021 06:45

Re: HDD size

#6 Post by MauricioDeAbreu » 28 Dec 2021 15:40

Compo, thanks for replying.

I have added this to the .Batch, I just need to see the results when the holidays are over.

I'll tell you how it all turned out.

Thankful as always for the help you give me.

MauricioDeAbreu
Posts: 38
Joined: 12 Dec 2021 06:45

Re: HDD size

#7 Post by MauricioDeAbreu » 16 Jan 2022 13:07

I apologize for the delay in responding, work activities increased to such an extent that I had not been able to do tests and enter the forum to report the results.

I also want to thank Compo, aGerman, and penpen for their input.

The codes worked as expected.

first method

Code: Select all

For /f "tokens=*" %%f in ('WMIC DiskDrive WHERE "DeviceID='\\\\.\\PHYSICALDRIVE0'" GET Size /value ^| find "="') do set "%%f"
second method

Code: Select all

SetLocal EnableExtensions DisableDelayedExpansion

For /F "Tokens=2 Delims=#," %%G in ('%SystemRoot%\System32\wbem\WMIC.exe
 LogicalDisk Where "DeviceID='%SystemDrive%'"
 Assoc /ResultClass:Win32_DiskPartition 2^>NUL'
) Do For /F "EOL=S" %%H In ('%SystemRoot%\System32\wbem\WMIC.exe DiskDrive Where
 "Index='%%G'" Get Size 2^>NUL') Do For %%I In (%%H) Do Set "SizeHDD=%%I"
Thank you as always for the help you have given me.

Resolved issue.

Jedininja
Posts: 25
Joined: 11 Jan 2022 22:41
Location: CanafukpilesDa
Contact:

Re: HDD size

#8 Post by Jedininja » 17 Jan 2022 05:19

Code: Select all

Wmic VOLUME GET freespace, capacity, serialnumber
may be helpful.
) Do For /F "EOL=S" %%H In ('%SystemRoot%\System32\wbem\WMIC.exe DiskDrive Where
/webm/ should very much not be there.
i once decrypted memtest.exe and found webm & webp tags itself all over ram sectors... same for bootconfig, it also clones desktop.ini
to test it, remove the power, bios batters, ram and hdd's and networkcards from your computer and let sit well out at the grocery store or something. i bet you your pc will run like a charm when u reassemble and boot up again (dont put you net-cards back in right away). i have a suspicion that webm/webp is imprinting a trojen client which is sectioning off ram and hdd space as i am "missing" 7 gigs of hd and 10megs of memory and i believe it to be the hijacker of my website and facebook page.


is the proper wmic:
C:\Windows\WinSxS\x86_microsoft-windows-w..ommand-line-utility_31bf3856ad364e35_10.0.17763.1_none_365123c06ca2ece1\wmic.exe

aGerman
Expert
Posts: 4433
Joined: 22 Jan 2010 18:01
Location: Germany

Re: HDD size

#9 Post by aGerman » 17 Jan 2022 12:09

is the proper wmic:
C:\Windows\WinSxS\x86_microsoft-windows-w..ommand-line-utility_31bf3856ad364e35_10.0.17763.1_none_365123c06ca2ece1\wmic.exe
Completely wrong! Once more! And - Do you really propose people to disassemble their PCs and remove their Bios battery?
Earn a four-week vacation from the forum for potentionally lead forum users to damage their system, if not their hardware.

Steffen

Locked