Bookmark

Donate

Subscribe

Subscribe to our RSS feed

Subscribe to our RSS feed
Email Subscription

Enter your Email ID:

Delivered by FeedBurner

Categories

Links

Log the available amount of free disk space to a file on a daily basis

Published: Sep 02, 2005
Send your feedback

Introduction

The following VBScript will log the free hard disk space (consolidated) information to a log file. You can configure this script to run from Windows Startup or even better, using Scheduled Task, to run it on a daily basis. The information will be stored in a file named FreeSpace.txt in the Desktop. You can change the path accordingly if you want to.

Here is the Script

'FreeSpaceInfo.vbs - September 2, 2005
'Author : Ramesh Srinivasan
'Website: https://www.winhelponline.com/xp
'Logs the free hard disk space info to a file.
'Can be run as a Scheduled task or placed at Startup folder.


Option Explicit
Dim iSpc, strComputer, objWMIService
Dim fso, fsHandle, MyShell,LogFileName, colItems, objItem
Set MyShell = CreateObject("Wscript.Shell")
Set fso = Wscript.CreateObject("Scripting.FilesystemObject")
LogFileName= MyShell.SpecialFolders("Desktop") & "\FreeSpace.txt"
set fsHandle = fso.OpenTextFile (LogFileName,8,True)

strComputer = "."
Set objWMIService = GetObject _
( "winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DriveType = 3")

For Each objItem in colItems
'Retrieve free space & convert from uint64
iSpc = cDbl(iSpc) + cDbl(objItem.FreeSpace)
Next

iSpc= iSpc/1024
iSpc= iSpc/1024
iSpc= iSpc/1024
iSpc= FormatNumber(iSpc,1)

'To capture the Date & Time, use "Now" function instead of "Date"
fsHandle.Writeline Date & " -- " & iSpc & " GB Free space"
fsHandle.Writeblanklines 1
fsHandle.close
set MyShell = Nothing
set fso = Nothing
 

Copy the above lines to Notepad, and save the file as "FreeSpaceInfo.vbs" (with quotes). You may then place this script at Windows Startup folder, or configure the script to run using Task Scheduler on a daily basis.

To capture the free space information for each drive, rather than a consolidated figure, use this script:

'FreeSpaceInfo2.vbs - September 3, 2005
'Author : Ramesh Srinivasan
'Website: https://www.winhelponline.com/xp
'Logs the free hard disk space info to a log file.
'Can be run as a Scheduled task or placed at Startup folder.


Option Explicit
Dim iSpc, strComputer, objWMIService
Dim fso, fsHandle, MyShell,LogFileName, colItems, objItem
Set MyShell = CreateObject("Wscript.Shell")
Set fso = Wscript.CreateObject("Scripting.FilesystemObject")
LogFileName= MyShell.SpecialFolders("Desktop") & "\FreeSpace.txt"
set fsHandle = fso.OpenTextFile (LogFileName,8,True)

fsHandle.Writeline Date
fsHandle.Writeblanklines 1
strComputer = "."
Set objWMIService = GetObject _
( "winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DriveType = 3")

For Each objItem in colItems
'Retrieve free space & convert from uint64
iSpc = cDbl(objItem.FreeSpace)
fsHandle.Writeline objItem.DeviceID & " - " _
& FormatiSpc(iSpc) & " GB free"
Next

Function FormatiSpc(intSpace)
  intSpace = intSpace/1024
  intSpace = intSpace/1024
  intSpace = intSpace/1024
  intSpace= FormatNumber(intSpace,1)
  FormatiSpc = intSpace
end function

fsHandle.Writeblanklines 2
fsHandle.close
set MyShell = Nothing
set fso = Nothing