amfony Posted April 9, 2008 Posted April 9, 2008 Hi guys, Currently re-writing a computer startup script for terminal computers and im abit stuck. I want to be able to run(), or better runwait() with a defrag analysis line (c:\windows\system32\defrag.exe -a c:) , then act accordingly with a defrag if "YOU NEED TO DEFRAGMENT THIS DRIVE" result is returned. I am having issues with returning anything of use from either run, shellexecute or runDos. With results returning either 0,1, or a random number in the 1000 - 5000 range. current line is simply: $var = _runDos("c:\windows\system32\defrag.exe -a c:") \n msgbox(1,"",$var) just to see where i am. Anyone have any ideas? or how i could achieve what i want? At the moment i am juggling with the idea of a forced defrag every friday shutdown, but that only because i cant figure out what i need to do here (programming wise) Thanks for any help.
rasim Posted April 9, 2008 Posted April 9, 2008 Try this: $Run = RunWait(@ComSpec & " /c defrag.exe c: -a>" & @TempDir & "\log.txt", @SystemDir, @SW_HIDE) $read = FileRead(@TempDir & "\log.txt") If StringRegExp($read, "(?i)(YOU NEED TO DEFRAGMENT THIS DRIVE)") Then MsgBox(48, "Defrag", "Need defrag")
MHz Posted April 9, 2008 Posted April 9, 2008 You could use StdOutRead() to get the string. Example: Global $data $pid = Run(@ComSpec & ' /c defrag.exe -a c:', @SystemDir, @SW_HIDE, 2); Stdout Do $data &= StdOutRead($pid) Until @error If StringInStr($data, 'YOU NEED TO DEFRAGMENT THIS DRIVE') Then RunWait(@ComSpec & ' /c defrag.exe c:') EndIf
Squirrely1 Posted April 9, 2008 Posted April 9, 2008 I like MHz's method, even though he used to be a communist. There was a potential antinomy checking for "DRIVE" or "VOLUME" for the $data variable. So you might prefer this: Global $data $pid = Run(@ComSpec & ' /c defrag.exe -a c:', @SystemDir, @SW_HIDE, 2); Stdout Do $data &= StdOutRead($pid) Until @error ;MsgBox(0, "", $data) If StringInStr($data, 'YOU DO NOT NEED TO DEFRAGMENT') Then $ret = MsgBox(32+3, "", _ "According to the demo-ware defragger that comes with" _ & @CR & "XP, drive C: does not need defragging. Defrag anyway? ") If $ret = 6 Then RunWait(@ComSpec & ' /c defrag.exe c:') EndIf Else RunWait(@ComSpec & ' /c defrag.exe c:') EndIf Das Häschen benutzt Radar
MadBoy Posted April 9, 2008 Posted April 9, 2008 Usage is simple: script.exe c: or script.exe all etc Thanks to this you don't have to use this on english only system. Althought it always does the defrag it's not so bad expandcollapse popup#cs Return codes: 0 - success (no errors were found) 1 - failure (some errors on drive) 2 - wrong parameters (can be only "all", "c:" or other drive letters 4 - failure (drive(s) not ready) #ce #cs Exit codes for DEFRAG (left for reference) 0 - Completed, no errors 1 - User aborted, cancelled 2 - Bad parameter, syntax error 3 - Unforeseen, unknown error 4 - Low memory condition (RAM) 5 - Not used (undefined), general error 6 - System, ACL, file mismatch, system wide error 7 - Low disk space, under 15% free on current volume #ce #include <array.au3> Global $array_special[1] If $CmdLine[0] = 1 Then If $CmdLine[1] = "All" Then $drive_array = DriveGetDrive("FIXED") If Not @error Then For $a = 1 To $drive_array[0] _ArrayAdd($array_special, $drive_array[$a]) Next Else Exit (1) EndIf Else If StringLen($CmdLine[1]) = 2 Then _ArrayAdd($array_special, $CmdLine[1]) Else Exit (2) EndIf EndIf $array_special[0] = UBound($array_special) - 1 For $a = 1 To $array_special[0] If DriveStatus($array_special[$a]) = "Ready" Then $run = RunWait(@ComSpec & ' /c defrag.exe -f ' & $array_special[$a], @SystemDir, @SW_HIDE) If $run = 0 Then ; Completed, no errors ; Continue.. everything is fine. Else Exit (1) EndIf Else Exit (4) ; Drive not ready EndIf Next Else Exit (2) EndIf Exit (0) My little company: Evotec (PL version: Evotec)
amfony Posted April 9, 2008 Author Posted April 9, 2008 thanks guys! very appreciative -- althought i dont know how communism was brought into the thread? but now its here - FREE TIBET!
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