Hi!
I currently work at a company that is looking to save some money, so I've been tasked with finding a cheap way to defrag the systems on the network. Since defrag.exe is part of Windows I figure a login script would be a perfect solution but we want a way to gather information. I figured the best was to use a defrag -a to do an analysis of the system and then act based on that. I'm finding it hard to find info on how to read out the information. I have a working script that does the defrag -a and outputs it to a log file, just not sure where to go from there to parse the file for the % total frag and the % file frag.
Option Explicit
Dim objShell, objProcEnv, sesDefrag
Set objShell = CreateObject("WScript.Shell")
Set objProcEnv = objShell.Environment("Process")
sesDefrag = objProcEnv("SessionName")
if sesDefrag = "" or LCase(sesDefrag) = "console" Then
objShell.Exec ("cmd /c del /F c:\defrag.log")
objShell.Exec ("cmd /c defrag -a c: > c:\defrag.log")
Dim filesys, demofile, createdate
Set filesys = CreateObject("Scripting.FileSystemObject")
Set demofile = filesys.GetFile("c:\defrag.log")
createdate = demofile.DateCreated
MsgBox "Created on " & createdate
End if
Set objShell = Nothing
Set objProcEnv = Nothing
WScript.Quit
I currently work at a company that is looking to save some money, so I've been tasked with finding a cheap way to defrag the systems on the network. Since defrag.exe is part of Windows I figure a login script would be a perfect solution but we want a way to gather information. I figured the best was to use a defrag -a to do an analysis of the system and then act based on that. I'm finding it hard to find info on how to read out the information. I have a working script that does the defrag -a and outputs it to a log file, just not sure where to go from there to parse the file for the % total frag and the % file frag.
Option Explicit
Dim objShell, objProcEnv, sesDefrag
Set objShell = CreateObject("WScript.Shell")
Set objProcEnv = objShell.Environment("Process")
sesDefrag = objProcEnv("SessionName")
if sesDefrag = "" or LCase(sesDefrag) = "console" Then
objShell.Exec ("cmd /c del /F c:\defrag.log")
objShell.Exec ("cmd /c defrag -a c: > c:\defrag.log")
Dim filesys, demofile, createdate
Set filesys = CreateObject("Scripting.FileSystemObject")
Set demofile = filesys.GetFile("c:\defrag.log")
createdate = demofile.DateCreated
MsgBox "Created on " & createdate
End if
Set objShell = Nothing
Set objProcEnv = Nothing
WScript.Quit