iamtheky Posted June 1, 2011 Posted June 1, 2011 (edited) any keen ways of detecting bare metal disk size? All my solutions seem to only function on formatted media. Edited June 2, 2011 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
BrewManNH Posted June 1, 2011 Posted June 1, 2011 I don't believe there's a way to detect that because different file systems have different overheads when they format a drive. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Tripredacus Posted June 1, 2011 Posted June 1, 2011 You can try WMI. I don't have a system I can test anything out on yet, but I'm looking at these as starting points.Win32_LogicalDiskWin32_DiskQuota Twitter | MSFN | VGCollect
GEOSoft Posted June 1, 2011 Posted June 1, 2011 Win32_DiskQuota won't do it with any drive I just tested Win32_LogicalDisk against a drive that I zero filled a couple of days ago and it can't be done that way either. I can get a return value for Size using Win32_DiskDrive but there is really no way to access it for a particular drive unless you know either the drive ID or the Index of the drive. Also the figure returned in that case is not correct. The tested drive is a little 120GB drive and the return value is 114.5GB although there is always some manufacturer overhead. You might be able to calculate it from CHST (Which is returned) but I forget the formula for doing it. Here is the AutoIt Scriptomatic code for it. I removed the date function and the reference to it because that function sucks and it won't return anything here anyway. I also did the calculation from bytes to Gbytes rounded to 2 decimal places. expandcollapse popup; Generated by AutoIt Scriptomatic June 01, 2011 $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output &= "Computer: " & $strComputer & @CRLF $Output &= "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output &= "Availability: " & $objItem.Availability & @CRLF $Output &= "BytesPerSector: " & $objItem.BytesPerSector & @CRLF $strCapabilities = $objItem.Capabilities(0) $Output &= "Capabilities: " & $strCapabilities & @CRLF $strCapabilityDescriptions = $objItem.CapabilityDescriptions(0) $Output &= "CapabilityDescriptions: " & $strCapabilityDescriptions & @CRLF $Output &= "Caption: " & $objItem.Caption & @CRLF $Output &= "CompressionMethod: " & $objItem.CompressionMethod & @CRLF $Output &= "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF $Output &= "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF $Output &= "CreationClassName: " & $objItem.CreationClassName & @CRLF $Output &= "DefaultBlockSize: " & $objItem.DefaultBlockSize & @CRLF $Output &= "Description: " & $objItem.Description & @CRLF $Output &= "DeviceID: " & $objItem.DeviceID & @CRLF $Output &= "ErrorCleared: " & $objItem.ErrorCleared & @CRLF $Output &= "ErrorDescription: " & $objItem.ErrorDescription & @CRLF $Output &= "ErrorMethodology: " & $objItem.ErrorMethodology & @CRLF $Output &= "FirmwareRevision: " & $objItem.FirmwareRevision & @CRLF $Output &= "Index: " & $objItem.Index & @CRLF ;$Output &= "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output &= "InterfaceType: " & $objItem.InterfaceType & @CRLF $Output &= "LastErrorCode: " & $objItem.LastErrorCode & @CRLF $Output &= "Manufacturer: " & $objItem.Manufacturer & @CRLF $Output &= "MaxBlockSize: " & $objItem.MaxBlockSize & @CRLF $Output &= "MaxMediaSize: " & $objItem.MaxMediaSize & @CRLF $Output &= "MediaLoaded: " & $objItem.MediaLoaded & @CRLF $Output &= "MediaType: " & $objItem.MediaType & @CRLF $Output &= "MinBlockSize: " & $objItem.MinBlockSize & @CRLF $Output &= "Model: " & $objItem.Model & @CRLF $Output &= "Name: " & $objItem.Name & @CRLF $Output &= "NeedsCleaning: " & $objItem.NeedsCleaning & @CRLF $Output &= "NumberOfMediaSupported: " & $objItem.NumberOfMediaSupported & @CRLF $Output &= "Partitions: " & $objItem.Partitions & @CRLF $Output &= "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $Output &= "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF $Output &= "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF $Output &= "SCSIBus: " & $objItem.SCSIBus & @CRLF $Output &= "SCSILogicalUnit: " & $objItem.SCSILogicalUnit & @CRLF $Output &= "SCSIPort: " & $objItem.SCSIPort & @CRLF $Output &= "SCSITargetId: " & $objItem.SCSITargetId & @CRLF $Output &= "SectorsPerTrack: " & $objItem.SectorsPerTrack & @CRLF $Output &= "SerialNumber: " & $objItem.SerialNumber & @CRLF $Output &= "Signature: " & $objItem.Signature & @CRLF $Output &= "Size: " & Round($objItem.Size/1024^3, 2) & "Gb" & @CRLF $Output &= "Status: " & $objItem.Status & @CRLF $Output &= "StatusInfo: " & $objItem.StatusInfo & @CRLF $Output &= "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF $Output &= "SystemName: " & $objItem.SystemName & @CRLF $Output &= "TotalCylinders: " & $objItem.TotalCylinders & @CRLF $Output &= "TotalHeads: " & $objItem.TotalHeads & @CRLF $Output &= "TotalSectors: " & $objItem.TotalSectors & @CRLF $Output &= "TotalTracks: " & $objItem.TotalTracks & @CRLF $Output &= "TracksPerCylinder: " & $objItem.TracksPerCylinder & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_DiskDrive" ) Endif George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
GEOSoft Posted June 1, 2011 Posted June 1, 2011 From a TestDisk page we also get thisUnder DOS, TestDisk gets the disk sizes using an extended BIOS function (ah=0x48, int 0x13), and geometry (number of heads and sectors) using a standard BIOS function (ah=0x08, int 0x13). TestDisk uses the default sector size of 512 bytes. Under Windows, TestDisk gets the numbers of cylinders, heads and sectors, and the sector size using the DeviceIoControl call, IOCTL_DISK_GET_DRIVE_GEOMETRY.Ref: http://www.cgsecurity.org/wiki/Menu_GeometryThat means that you can get the geometry with a dll call but you would still have to do the calculations to get the size.Someone else can come along and give you the DLL call to get the info.Just found the calculation based on the standard 512 bytes per sectorsectorbytes = 512bytes = sectorbytes * sectors * cylinders * heads George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
iamtheky Posted June 1, 2011 Author Posted June 1, 2011 Thank you, that works nicely in session and will be a excellent snippet to keep. However, i failed to mention that I am attempting this from a WinPE environment which has no love for WMI (no object). All apologies for my lack of clear direction and/or my clear lack of direction ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Tripredacus Posted June 1, 2011 Posted June 1, 2011 Is there a reason you haven't added the WMI Package into your WinPE? Twitter | MSFN | VGCollect
iamtheky Posted June 1, 2011 Author Posted June 1, 2011 getting there, hadnt had a need up till now.. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
BrewManNH Posted June 1, 2011 Posted June 1, 2011 Why do you need the unformatted size of a drive anyways? Just curious, because the information isn't of much use because the formatted size is always less, and that depends on what file system you use to format it. If you're really interested in such things, crack the case open and look at the drive label, it's always on there somewhere. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
UEZ Posted June 1, 2011 Posted June 1, 2011 Maybe Diskpart will help.Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
iamtheky Posted June 1, 2011 Author Posted June 1, 2011 (edited) Why do you need the unformatted size of a drive anyways?Solid question.I have a fork in the road that detects drive size and then diskparts accordingly. This worked charmingly until they dropped the image on a virtualbox with a new disk. Even if you create a static disk there is no proper return (that i have found yet). **no format is conducted up front because if the drive does not meet minimum requirements the load is refused, prefer not to wipe their drive and then reject it**So i was looking for a way to determine drive size regardless of data, then go do the fork.@Uez - "list disk" up front might do the trick, just have to pipe that size out somewhere usable. Thanks for the recommendations/questions, they are forcing me to explore more options. Edited June 1, 2011 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Tripredacus Posted June 1, 2011 Posted June 1, 2011 (edited) I'm probably going to need something like this as well for my deployment code. We had ordered a 3TB drive from corporate but haven't gotten it yet. We've already ran into situations where the normal deployment would make a 2TB partition on a 3TB drive because diskpart's default formatting type uses MBR. So I'm thinking (have planned this a while now but no drive to test on yet) that my app can detect the drive size, if over 2TB, prompt to install as GPT. I already know how the entire process works, and a pretty good idea how to automate it. But oh about the WinPE, I always build mine with all the extra packages in them. To quote:This adds the HTA, MDAC, Scripting and WMI packages. The MDAC may or may not be required for you, but not having it only can limit future developmentFrom here. So I've always taken the presence of WMI for granted. EDIT: regarding the diskpart automation, I had already checked the SDK for OPK and it doesn't cover anything for Diskpart. I think the main problem might be that when you run Diskpart it runs as a shell, which just means you always need to make it exit. You could probably do a "diskpart /s findsize.txt > result.txt" then do a string read off that file. Edited June 1, 2011 by Tripredacus Twitter | MSFN | VGCollect
iamtheky Posted June 1, 2011 Author Posted June 1, 2011 thanks for the link, i really should spend more time over there. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
rover Posted June 1, 2011 Posted June 1, 2011 (edited) code from WinAPIEx.au3 example folder works in WinPE 2.0 #Include <WinAPIEx.au3> Opt('MustDeclareVars', 1) Global $tDISK_GEOMETRY_EX, $Drive = 0 While 1 $tDISK_GEOMETRY_EX = _WinAPI_GetDriveGeometryEx($Drive) If @error Then ExitLoop EndIf If Not $Drive Then ConsoleWrite('-------------------------------' & @CR) EndIf ConsoleWrite('Drive: ' & $Drive & @CR) ConsoleWrite('Cylinders: ' & DllStructGetData($tDISK_GEOMETRY_EX, 'Cylinders') & @CR) ConsoleWrite('Tracks per Cylinder: ' & DllStructGetData($tDISK_GEOMETRY_EX, 'TracksPerCylinder') & @CR) ConsoleWrite('Sectors per Track: ' & DllStructGetData($tDISK_GEOMETRY_EX, 'SectorsPerTrack') & @CR) ConsoleWrite('Bytes per Sector: ' & DllStructGetData($tDISK_GEOMETRY_EX, 'BytesPerSector') & ' bytes' & @CR) ConsoleWrite('Total Space: ' & DllStructGetData($tDISK_GEOMETRY_EX, 'DiskSize') & ' bytes' & @CR& @CR) ConsoleWrite('-------------------------------' & @CR) $Drive +=1 WEnd Edited June 1, 2011 by rover meoit 1 I see fascists...
BrewManNH Posted June 1, 2011 Posted June 1, 2011 Would this function be of any use for an unformatted drive because unformatted drives have no drive letter? Or does it work by drive number as well, as the example you posted used, because the function you used said it needs a drive letter. Does a non-formatted, non-fdisk'ed drive have a drive number to the OS? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
rover Posted June 2, 2011 Posted June 2, 2011 Would this function be of any use for an unformatted drive because unformatted drives have no drive letter? Or does it work by drive number as well, as the example you posted used, because the function you used said it needs a drive letter.Does a non-formatted, non-fdisk'ed drive have a drive number to the OS?It's an error in the documentation.If you look at the function you would see it calls CreateFileEx with a physical drive number 0,1,2...and yes it works with unformatted drives, even on a WinPE platform.just a few API calls to kernel32.dlland no drive letter for a unformatted disk. I see fascists...
BrewManNH Posted June 2, 2011 Posted June 2, 2011 Very useful. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
iamtheky Posted June 2, 2011 Author Posted June 2, 2011 (edited) APIex is the big winner, even handles 'dynamic expanding disks' inside virtual machines (with a tolerable discrepancy between reported and actual). Thanks Rover Edited June 2, 2011 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now