'Logs the free hard disk space info to a log file.
On Error Resume Next
Message = "This script will Write a file (FreeSpace.txt) on your Desktop." & vbCr _
 & "You can open the file with Notepad." & vbCr & vbCr _
 & "Continue?"

X = MsgBox(Message, vbYesNo + vbInformation, "Paul's XP and Vista Tweaks")
If X = 6 Then 

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 ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
fsHandle.WriteLine ("This is a list of free space on your harddrives")
fsHandle.WriteLine ("Visit www.paulsxp.com")
fsHandle.WriteLine ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
fsHandle.WriteLine  Date 
fsHandle.WriteLine Time
fsHandle.WriteLine ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
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.WriteLine ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
fsHandle.WriteBlankLines 2
fsHandle.Close
Set MyShell = Nothing
Set fso = Nothing
Title = "The file FreeSpace.txt is now on your Desktop." & vbCr _
 & "Ths script was downloaded from www.paulsxp.com."
MyBox = MsgBox(Title, 64, "Finished")
End If