Moderators JLogan3o13 Posted July 9, 2010 Moderators Share Posted July 9, 2010 [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.DrivesFor $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) EndIfNextCall( "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" ) EndIfEndFuncFunc 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 )EndFuncFileDelete( $Log ) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! 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