mac_shinobi Posted March 22, 2012 Posted March 22, 2012 (edited) I have tried a number of different wmi classes and also the file system object to get the capacity of a hard drive yet it is always showing the available space of said drive so for example My work PC has a 160 Gb Hard Drive ( yes un formatted capacity , not taking into consideration windows file system uses x amount and etc etc ) Yet when trying any of the wmi classes win32_Disk, win32_LogicalDisk and any where else I try to get the drive capacity of my main hard drive it either shows up as 148.6 Gb or 149 Gb Same for other capacity hard drives ie 320 shows up as lot lower , 80 shows up as 74 gb etc Which script or what do I have to do to make it show up the true unformatted capacity ( not taking into consideration that windows uses x amount for the FS etc ) Edited March 22, 2012 by mac_shinobi
FN-GM Posted March 22, 2012 Posted March 22, 2012 You might be able to pinch something from this - http://www.edugeek.net/forums/scripts/32287-inventory-your-network.html 1
themightymrp Posted March 22, 2012 Posted March 22, 2012 Somebody at this site makes use of an AutoIT script: [sOLVED] detect unformatted disk size - AutoIt Forums Might help
mac_shinobi Posted March 22, 2012 Author Posted March 22, 2012 (edited) Somebody at this site makes use of an AutoIT script: [sOLVED] detect unformatted disk size - AutoIt Forums Might help Slightly, it has given me this formula but am not sure which items or which wmi class to use to get these things from the formula sectorbytes = 512 bytes = sectorbytes * sectors * cylinders * heads Looking at Win32_DiskDrive Win32_DiskDrive class There are a few things there but with different names, any ideas on which ones are which ? As per below class Win32_DiskDrive : uint32 BytesPerSector; uint64 TotalCylinders; uint32 TotalHeads; uint64 TotalSectors; uint64 TotalTracks; uint32 TracksPerCylinder;}; Only properties / methods I can see that may be related but again not sure if or which ones are the ones I need Doing this for an inventory and would be good to see it output 80 Gb instead of 74 Gb because I want to know the actual capacities un formatted so I can say oh that one has a 160 Gb not a 148.9 Gb and have to think ok is that 160 or 150 or what exactly Edited March 22, 2012 by mac_shinobi
mac_shinobi Posted March 22, 2012 Author Posted March 22, 2012 You might be able to pinch something from this - http://www.edugeek.net/forums/scripts/32287-inventory-your-network.html Checked and yours is exactly the same, shows up as 148 Gb instead of 160 Gb
Steve21 Posted March 22, 2012 Posted March 22, 2012 Without sounding rude, I think you're missing the point When harddrives are sold it's usually based upon 1000 bytes per kb etc, not 1024. aka 149 * 1024 * 1024 * 1024 = 1.59988E+11 however manufactuers go 1.59988E+11 /1000 /1000 /1000 = 160gb So if you want to convert 149GB to 160GB you can just do it through the dividing and timising out, but it depends what you call the "true" size Steve
Steve21 Posted March 22, 2012 Posted March 22, 2012 Option Explicit Dim objWMIService, objItem, colItems, strComputer strComputer = "." Set objWMIService = GetObject("winmgmts:\\" _ & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery(_ "Select * from Win32_DiskDrive") For Each objItem in colItems Wscript.Echo "Computer: " & objItem.SystemName & VbCr & _ "RealSize: " & Int(objItem.Size /(1073741824)) & " GB" & VbCr & _ "ManuSize: " & Int(objItem.Size /(1000000000)) & " GB" Next WSCript.Quit Example above, Steve
mac_shinobi Posted March 22, 2012 Author Posted March 22, 2012 Option Explicit Dim objWMIService, objItem, colItems, strComputer strComputer = "." Set objWMIService = GetObject("winmgmts:\\" _ & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery(_ "Select * from Win32_DiskDrive") For Each objItem in colItems Wscript.Echo "Computer: " & objItem.SystemName & VbCr & _ "RealSize: " & Int(objItem.Size /(1073741824)) & " GB" & VbCr & _ "ManuSize: " & Int(objItem.Size /(1000000000)) & " GB" Next WSCript.Quit Example above, Steve That makes a bit more sense, although need that adjusting so it only checks the main hard drive so Drive zero not any additional drives ie memory sticks / memory stick usb drives etc
Steve21 Posted March 22, 2012 Posted March 22, 2012 That makes a bit more sense, although need that adjusting so it only checks the main hard drive so Drive zero not any additional drives ie memory sticks / memory stick usb drives etc Option Explicit Dim objWMIService, objItem, colItems, strComputer strComputer = "." Set objWMIService = GetObject("winmgmts:\\" _ & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery(_ "select * from Win32_DiskDrive where Name like '%PHYSICALDRIVE0%'") For Each objItem in colItems Wscript.Echo "Computer: " & objItem.SystemName & VbCr & _ "RealSize: " & Int(objItem.Size /(1073741824)) & " GB" & VbCr & _ "ManuSize: " & Int(objItem.Size /(1000000000)) & " GB" Next WSCript.Quit should do it. Assuming it's named as normal steve 1
mac_shinobi Posted March 22, 2012 Author Posted March 22, 2012 (edited) Script that I have has been adjusted to the below then : const HKEY_CURRENT_USER = &H80000001 const HKEY_LOCAL_MACHINE = &H80000002 Const ForReading = 1, ForWriting = 2, ForAppending = 8 strComputer = "." Set StdOut = WScript.StdOut Dim username, Model, serial, asset, hdd, manuhdd, manu Dim strRAM dim filesys, filetxt dim newfolder Dim usbPath, FullPath Set objNetwork = CreateObject("Wscript.Network") Set filesys = CreateObject("Scripting.FileSystemObject") username = objNetwork.username strComputer = objNetwork.ComputerName usbPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") FullPath = usbPath & "logs\" If Not filesys.FolderExists(FullPath) Then newfolder = filesys.CreateFolder (FullPath) Wscript.Echo "A new folder '" & newfolder & "' has been created" End If Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) For Each Item In colItems manu = Item.Manufacturer model = Item.Model strRam = ConvertSize(Item.TotalPhysicalMemory) Next Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS") For Each objItem in colItems serial = objItem.SerialNumber Next Set colItems = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure") For Each objItem in colItems asset = objItem.SMBIOSAssetTag Next Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv") strKeyPath = "HARDWARE\DESCRIPTION\System\CentralProcessor\0" strValue = "ProcessorNameString" objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValue,strScriptStatus Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery("select * from Win32_DiskDrive where Name like '%PHYSICALDRIVE0%'") For Each objDisk in colDisks hdd = ConvertSize(objDisk.Size) manuhdd = Int(objDisk.Size /(1000000000)) & " GB" Next Set filetxt = filesys.OpenTextFile(FullPath & ucase(username) & ".txt" , ForAppending, True) filetxt.WriteLine "Username,Manufacturer,Serial Number,Model,Computer Name,RAM,HDD,Asset Tag,Processor" filetxt.WriteLine ucase(username) & "," & manu & "," & serial & "," & model & "," & strComputer & "," & strRAM & "," & hdd & "( " & manuhdd & " )" & "," & asset & "," & strScriptStatus filetxt.Close msgbox ucase(username) & vbcrlf & manu & vbcrlf & model & vbcrlf & serial & vbcrlf & asset & vbcrlf & vbcrlf & strComputer & vbcrlf & strScriptStatus & vbcrlf & strRAM & vbcrlf & hdd & "( " & manuhdd & " )" wscript.sleep 1000 Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set FileList = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_Directory.Name='" & usbPath & "logs" & "'} Where ResultClass = CIM_DataFile") For Each objFile In FileList If objFile.Extension = "txt" Then strNewName = objFile.Drive & objFile.Path & _ objFile.FileName & "." & "csv" errResult = objFile.Rename(strNewName) If errResult <> "0" Then Wscript.Echo errResult else Wscript.Echo "Conversion to CSV Completed" End If End If Next Function ConvertSize(Size) Do While InStr(Size,",") 'Remove commas from size CommaLocate = InStr(Size,",") Size = Mid(Size,1,CommaLocate - 1) & _ Mid(Size,CommaLocate + 1,Len(Size) - CommaLocate) Loop Suffix = " Bytes" If Size >= 1024 Then suffix = " KB" If Size >= 1048576 Then suffix = " MB" If Size >= 1073741824 Then suffix = " GB" If Size >= 1099511627776 Then suffix = " TB" Select Case Suffix Case " KB" Size = Round(Size / 1024, 1) Case " MB" Size = Round(Size / 1048576, 1) Case " GB" Size = Round(Size / 1073741824, 1) Case " TB" Size = Round(Size / 1099511627776, 1) End Select ConvertSize = Size & Suffix End Function Set objMemory = Nothing Set objWMIService = Nothing Only thing left is to check if it is a dell or lenovo first before grabbing the info as the dell machines dont have an asset tag assigned vs the lenovos which do but thats a minor patch / fix At the start of the script it has : Set StdOut = WScript.StdOut What on earth does that do or what is that used for ? Edited March 22, 2012 by mac_shinobi
Steve21 Posted March 22, 2012 Posted March 22, 2012 Set StdOut = WScript.StdOut What on earth does that do or what is that used for ? This goes back to WScript vs CScript. If you're running it through commandline stdout is console etc etc. Steve
mac_shinobi Posted March 22, 2012 Author Posted March 22, 2012 This goes back to WScript vs CScript. If you're running it through commandline stdout is console etc etc. Steve Does that really need to be in the script or what exactly ?
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