Jump to content
Sign in to follow this  
JLogan3o13

Intermittent Errors on a Defrag app

Recommended Posts

JLogan3o13

[font="Arial"][size="2"]I've been playing around with an automated disk Analyze/Defrag tool. On a couple of machines it works just great, but on others it'll error out with "[b]The requested action with this object has failed[/b]." on line 10. I've been trying to figure out what could be different, as all the machines are XP SP3 from a common image, but am coming up with zip thus far. I'm enabling more in the way of error checking, but if anyone has some thoughts or suggestions, I would appreciate it greatly.

[/size][/font]

$Log = "C:\Temp\Defrag.log"

Const $DriveTypeRemovable = 1, $DriveTypeFixed = 2, $DriveTypeNetwork = 3, $DriveTypeCDROM = 4, $DriveTypeRAMDisk = 5

$FSO = ObjCreate("Scripting.FileSystemObject")

$Drives = $FSO.Drives

For $Drive in $Drives

If $Drive.DriveType = 2 Then

$WshShell = ObjCreate("WScript.Shell") < - - - this is the line it is erroring out on...

$RunString1 = "%comspec% /c echo "

$RunString2 = "%comspec% /c %WINDIR%\System32\Defrag.exe " & "C:" & " -a -v"

$WshShell.Run($RunString1 & " >> " & $Log & " 2>&1", 0, TRUE)

$WshShell.Run($RunString2 & " >> " & $Log & " 2>&1", 0, TRUE)

EndIf

Next

Call( "analyze" )

Func analyze()

$line = FileReadLine($Log, 15)

$value = StringTrimLeft($line,39)

If $value > "0 %" Then

$msg = MsgBox(1, "System Watcher", "Your Hard Drive is currently " & $value & " fragmented. This can cause poor performance." & @CRLF & "Click OK to defragment your Hard Drive now, or click Cancel to delay this action 30 minutes.")

Else

FileDelete( $Log )

EndIf

If $msg = 1 Then

Call( "defrag" )

Else

Sleep( 180000 )

Call( "defrag" )

EndIf

EndFunc

Func defrag()

$WshShell = ObjCreate("WScript.Shell")

$RunString1 = "%comspec% /c echo "

$RunString2 = "%comspec% /c %WINDIR%\System32\Defrag.exe " & "C:" & " -f"

$WshShell.Run($RunString1 & " >> " & $Log & " 2>&1", 0, TRUE)

$WshShell.Run($RunString2 & " >> " & $Log & " 2>&1", 0, TRUE)

FileDelete( $Log )

EndFunc

FileDelete( $Log )


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

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
Sign in to follow this  

×