sukendn Posted March 16, 2016 Share Posted March 16, 2016 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 Link to comment Share on other sites More sharing options...
water Posted March 16, 2016 Share Posted March 16, 2016 Use this script - generated by Scriptomatic - to get the drive properties: expandcollapse popup; 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted March 16, 2016 Share Posted March 16, 2016 And this to get the page file usage: expandcollapse popup; 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
sukendn Posted March 16, 2016 Author Share Posted March 16, 2016 I do Autoit beginner , you put the code so they 're very hard to do. Hope you suggest me easier . Thanks Link to comment Share on other sites More sharing options...
MuffinMan Posted March 16, 2016 Share Posted March 16, 2016 @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") Link to comment Share on other sites More sharing options...
sukendn Posted March 16, 2016 Author Share Posted March 16, 2016 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 Link to comment Share on other sites More sharing options...
MuffinMan Posted March 16, 2016 Share Posted March 16, 2016 Happy to help! Link to comment Share on other sites More sharing options...
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