sukendn

Calculate the total size of the Free Disk Space and file pagefile.sys

7 posts in this topic

 

I want to calculate the total size of the Free Disk Space and pagefile.sys file . But how many times have not been . Hope you help me . Here is my code :

$iFileGetSize = FileGetSize ( "C:\pagefile.sys" )
$Free = DriveSpaceFree( "c:\" )
$Used = $Free + $iFileGetSize
MsgBox(0, "", " Is Using " & $Used  & " MB")

Thanks

Share this post


Link to post
Share on other sites



Use this script - generated by Scriptomatic - to get the drive properties:

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "."

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "Access: " & $objItem.Access & @CRLF
      $Output = $Output & "Availability: " & $objItem.Availability & @CRLF
      $Output = $Output & "BlockSize: " & $objItem.BlockSize & @CRLF
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "Compressed: " & $objItem.Compressed & @CRLF
      $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
      $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
      $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF
      $Output = $Output & "DriveType: " & $objItem.DriveType & @CRLF
      $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
      $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
      $Output = $Output & "ErrorMethodology: " & $objItem.ErrorMethodology & @CRLF
      $Output = $Output & "FileSystem: " & $objItem.FileSystem & @CRLF
      $Output = $Output & "FreeSpace: " & $objItem.FreeSpace & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
      $Output = $Output & "MaximumComponentLength: " & $objItem.MaximumComponentLength & @CRLF
      $Output = $Output & "MediaType: " & $objItem.MediaType & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "NumberOfBlocks: " & $objItem.NumberOfBlocks & @CRLF
      $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
      $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
      $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
      $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
      $Output = $Output & "ProviderName: " & $objItem.ProviderName & @CRLF
      $Output = $Output & "Purpose: " & $objItem.Purpose & @CRLF
      $Output = $Output & "QuotasDisabled: " & $objItem.QuotasDisabled & @CRLF
      $Output = $Output & "QuotasIncomplete: " & $objItem.QuotasIncomplete & @CRLF
      $Output = $Output & "QuotasRebuilding: " & $objItem.QuotasRebuilding & @CRLF
      $Output = $Output & "Size: " & $objItem.Size & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF
      $Output = $Output & "SupportsDiskQuotas: " & $objItem.SupportsDiskQuotas & @CRLF
      $Output = $Output & "SupportsFileBasedCompression: " & $objItem.SupportsFileBasedCompression & @CRLF
      $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
      $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF
      $Output = $Output & "VolumeDirty: " & $objItem.VolumeDirty & @CRLF
      $Output = $Output & "VolumeName: " & $objItem.VolumeName & @CRLF
      $Output = $Output & "VolumeSerialNumber: " & $objItem.VolumeSerialNumber & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_LogicalDisk" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

And this to get the page file usage:

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "."

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PageFileUsage", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "AllocatedBaseSize: " & $objItem.AllocatedBaseSize & @CRLF
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "CurrentUsage: " & $objItem.CurrentUsage & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "PeakUsage: " & $objItem.PeakUsage & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      $Output = $Output & "TempPageFile: " & $objItem.TempPageFile & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PageFileUsage" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

 

I do Autoit beginner , you put the code so they 're very hard to do. Hope you suggest me easier . Thanks

Share this post


Link to post
Share on other sites

@sukendn,

Your first code worked fine for me on a Windows 7 box, but in the 2 functions you used, one returned the size in bytes and the other in MB - is that why it is not working correctly for you?  Try this code and see if it works:

$iFileGetSize = Round(FileGetSize( "C:\pagefile.sys" )/1048576,2)  ;Returns file size in bytes
$Free = Round(DriveSpaceFree( "c:\" ),2) ;Returns Free space in MB
$Used = Round($Free + $iFileGetSize,2)
MsgBox(0, "Stats", "Free Space on C : " & $Free & " MB" & @CRLF & "Size of Pagefile : " & $iFileGetSize & " MB" & @CRLF & "Total For Both : " & $Used & " MB")

 

Share this post


Link to post
Share on other sites
15 minutes ago, MuffinMan said:

@sukendn,

Your first code worked fine for me on a Windows 7 box, but in the 2 functions you used, one returned the size in bytes and the other in MB - is that why it is not working correctly for you?  Try this code and see if it works:

$iFileGetSize = Round(FileGetSize( "C:\pagefile.sys" )/1048576,2)  ;Returns file size in bytes
$Free = Round(DriveSpaceFree( "c:\" ),2) ;Returns Free space in MB
$Used = Round($Free + $iFileGetSize,2)
MsgBox(0, "Stats", "Free Space on C : " & $Free & " MB" & @CRLF & "Size of Pagefile : " & $iFileGetSize & " MB" & @CRLF & "Total For Both : " & $Used & " MB")

 

 

Thank you , it works very well

Share this post


Link to post
Share on other sites

Happy to help!

Share this post


Link to post
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