+ Post New Thread
Results 1 to 13 of 13
Scripts Thread, hard drive capacity - vbscript in Coding and Web Development; I have tried a number of different wmi classes and also the file system object to get the capacity of ...
  1. #1

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,896
    Thank Post
    3,417
    Thanked 1,081 Times in 997 Posts
    Rep Power
    369

    hard drive capacity - vbscript

    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 )
    Last edited by mac_shinobi; 22nd March 2012 at 02:05 PM.

  2. #2

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,203
    Thank Post
    893
    Thanked 1,773 Times in 1,529 Posts
    Blog Entries
    12
    Rep Power
    461
    You might be able to pinch something from this - Inventory Your network

  3. Thanks to FN-GM from:

    mac_shinobi (22nd March 2012)

  4. #3
    themightymrp's Avatar
    Join Date
    Dec 2009
    Location
    Leeds, West Yorkshire
    Posts
    1,256
    Thank Post
    218
    Thanked 231 Times in 200 Posts
    Rep Power
    74
    Somebody at this site makes use of an AutoIT script:

    [SOLVED] detect unformatted disk size - AutoIt Forums

    Might help

  5. #4

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,896
    Thank Post
    3,417
    Thanked 1,081 Times in 997 Posts
    Rep Power
    369
    Just looking now - thanks

  6. #5

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,896
    Thank Post
    3,417
    Thanked 1,081 Times in 997 Posts
    Rep Power
    369
    Quote Originally Posted by themightymrp View Post
    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
    Last edited by mac_shinobi; 22nd March 2012 at 02:28 PM.

  7. #6

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,896
    Thank Post
    3,417
    Thanked 1,081 Times in 997 Posts
    Rep Power
    369
    Quote Originally Posted by FN-GM View Post
    You might be able to pinch something from this - Inventory Your network
    Checked and yours is exactly the same, shows up as 148 Gb instead of 160 Gb

  8. #7

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,717
    Thank Post
    341
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    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

  9. #8

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,717
    Thank Post
    341
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Code:
    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

  10. #9

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,896
    Thank Post
    3,417
    Thanked 1,081 Times in 997 Posts
    Rep Power
    369
    Quote Originally Posted by Steve21 View Post
    Code:
    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

  11. #10

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,717
    Thank Post
    341
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Quote Originally Posted by mac_shinobi View Post
    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
    Code:
    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

  12. Thanks to Steve21 from:

    mac_shinobi (22nd March 2012)

  13. #11

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,896
    Thank Post
    3,417
    Thanked 1,081 Times in 997 Posts
    Rep Power
    369
    Script that I have has been adjusted to the below then :

    Code:
    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 ?
    Last edited by mac_shinobi; 22nd March 2012 at 04:21 PM.

  14. #12

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,717
    Thank Post
    341
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Quote Originally Posted by mac_shinobi View Post
    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

  15. #13

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,896
    Thank Post
    3,417
    Thanked 1,081 Times in 997 Posts
    Rep Power
    369
    Quote Originally Posted by Steve21 View Post
    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 ?

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 13
    Last Post: 28th January 2013, 07:25 PM
  2. Any suggestions on fibar hard drive.
    By tosca925 in forum Hardware
    Replies: 5
    Last Post: 25th July 2006, 11:30 AM
  3. Prevent hard drive changes
    By adamyoung in forum How do you do....it?
    Replies: 70
    Last Post: 20th June 2006, 12:32 PM
  4. LNM failed to format hard drives
    By wesleyw in forum Learning Network Manager
    Replies: 8
    Last Post: 29th April 2006, 08:26 AM
  5. Formating/Partioning a Hard drive
    By SimpleSi in forum *nix
    Replies: 9
    Last Post: 14th November 2005, 02:22 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •