Sign in to follow this  
Followers 0
want2becoder

error defrag analysis doesn't work under windows 7

9 posts in this topic

#1 ·  Posted (edited)

Not sure why I'm getting a below error with defrag command on windows 7...

Suggestions?

....Analyzing System Fragmentation Level...Please wait

- Error Running Defrag Analysis on C: with Process Id: 0

- An error occurred performing a fragmentation analysis on 'C:'

script

$Pid = Run(@ComSpec & 'defrag.exe /a /c ' & $DrivetoCheck, @SystemDir, @SW_HIDE, 2) ; Run defrag on c: drive. We only have c: drive to encrypt. So don't worry about multiple

Do ; Grab data from CLI

$Data &= StdOutRead($Pid)

Until @error

;_WriteLogFile("Stop Defrag Analysis " & $DrivetoCheck) ; Write log file

;MsgBox(0, "", $data) ; Debug see what is grabbed

If $Data = "" Then ; Must be an issue since there should be data

;_WriteLogFile("Error Running Defrag " & $DrivetoCheck & " " &$Pid) ; Write log file

StatusWindow_SetText( " - Error Running Defrag Analysis on " & $DriveToCheck & " with Process Id: " & $Pid, True )

;MsgBox( 16, "Defrag Analysis Error", "Error Running Defrag Analysis on " & $DriveToCheck & " with Process Id: " & $Pid )

Return 101 ;Return 101% fragmentation so it can be handled in error messages

EndIf

$retVal = StringSplit($Data, ",") ; Split data up into array using , as delimiter

;_ArrayDisplay($retVal, "First Array with comma") ; Debug See Array

$Fragit=$retVal[4] ; Element 4 is where the meat is. Lists frag levels

$retVal=StringSplit($Fragit, "%") ; Split it at % - Just grab Numeric

;_ArrayDisplay($retVal) ; Debug

$FragPercentage = StringStripWS($retVal[1],8) ; Remove white Space

;_WriteLogFile($DrivetoCheck & " is " & $FragPercentage & "% Fragmented") ; Write log file

;$FileFragLevel = $retVal[2] ; File Frag

;$retVal=StringSplit($FileFragLevel, "(") ; Split at ( so we just have the numeric

;$FileFragLevelpercentage = StringStripWS($retVal[2],8) ; Remove white Space

;MsgBox(0, "", $FileFragLEvelpercentage) ; Debug

;_WriteLogFile($DrivetoCheck & " is " & $FileFragLEvelpercentage & "% File Fragmented"); Write log file

Return $FragPercentage

EndFunc

error

Analyzing System Fragmentation Level...Please wait

- Error Running Defrag Analysis on C: with Process Id: 0

- An error occurred performing a fragmentation analysis on 'C:'

Edited by want2becoder

Share this post


Link to post
Share on other sites



Have you tried running the defrag command in a prompt on it own? I know it small but might help, make the /a uppercase to /A and remove the /c as you said you said you just wanted to defrag c: and /c runs on all volumes.

Also you launching of the command (your $pid) im positive the help file says you need to use comspec /c

heres my command that will change depending on OS

If @OSVersion = "WIN_7" Then

$DefragPath = " /c defrag.exe " & $SystemDrive & " /A /U"

Else

$DefragPath = " /c defrag.exe " & $SystemDrive & " -a "

EndIf

$pid = Run(@ComSpec & $DefragPath, @SystemDir, @SW_HIDE, 2); Stdout


Drunken Frat-Boy Monkey Garbage

Share this post


Link to post
Share on other sites

Thank you for the input..

The script was orginaly designed for 32 OS.

Right now I'm breaking down the script into version 32 xp and 64 windows 7. Once I get 64bit working. I will combine the script into one.

i.e if osarch=win7 ..

Also the checkdisk command that write to window events changed. i.e the event source" is Wininit (Windows Initialization) not winlogon..

Have you tried running the defrag command in a prompt on it own? I know it small but might help, make the /a uppercase to /A and remove the /c as you said you said you just wanted to defrag c: and /c runs on all volumes.

Also you launching of the command (your $pid) im positive the help file says you need to use comspec /c

heres my command that will change depending on OS

If @OSVersion = "WIN_7" Then

$DefragPath = " /c defrag.exe " & $SystemDrive & " /A /U"

Else

$DefragPath = " /c defrag.exe " & $SystemDrive & " -a "

EndIf

$pid = Run(@ComSpec & $DefragPath, @SystemDir, @SW_HIDE, 2); Stdout

Share this post


Link to post
Share on other sites

I still get the same error with recommend changes.

- Error Running Defrag Analysis on C: with Process Id: 0

- An error occurred performing a fragmentation analysis on 'C

Share this post


Link to post
Share on other sites

it looks that I was able to get pass the defrag command.. using recommended command.

defrag.exe c: /A /U

but now I'm getting

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\mvp\Desktop\hta\Install_MobileArmor64bit.au3"

C:\Users\mvp\Desktop\hta\Install_MobileArmor64bit.au3 (284) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$Fragit=$retVal[4]

$Fragit=^ ERROR

Share this post


Link to post
Share on other sites

I ran the command via the command line...

C:\Windows\system32>defrag c: /A

Microsoft Disk Defragmenter

Copyright © 2007 Microsoft Corp.

Invoking analysis on (C:)...

The operation completed successfully.

Post Defragmentation Report:

Volume Information:

Volume size = 931.41 GB

Free space = 859.24 GB

Total fragmented space = 0%

Largest free space size = 451.17 GB

Note: File fragments larger than 64MB are not included in the fragmentat

ion statistics.

You do not need to defragment this volume.

so error is specific

C:\Users\mvp\Desktop\hta\Install_MobileArmor64bit.au3 (283) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$Fragit=$retVal[4]

$Fragit=^ ERROR

code

$Fragit=$retVal[4] ; Element 4 is where the meat is. Lists frag levels

$retVal=StringSplit($Fragit, "%") ; Split it at % - Just grab Numeric

;_ArrayDisplay($retVal) ; Debug

$FragPercentage = StringStripWS($retVal[1],8) ; Remove white Space

;_WriteLogFile($DrivetoCheck & " is " & $FragPercentage & "% Fragmented") ; Write log file

$Fragit=$retVal[4] ; Element 4 is where the meat is. Lists frag levels

$retVal=StringSplit($Fragit, "%") ; Split it at % - Just grab Numeric

;_ArrayDisplay($retVal) ; Debug

$FragPercentage = StringStripWS($retVal[1],8) ; Remove white Space

;_WriteLogFile($DrivetoCheck & " is " & $FragPercentage & "% Fragmented") ; Write log file

Share this post


Link to post
Share on other sites

under windows xp works fine but not windows 7

Share this post


Link to post
Share on other sites

it looks that I need to compile the defrag.exe to 64bit also to make the command to work in native 64bit os.

Share this post


Link to post
Share on other sites

When running the command line from a 32bit AutoIt script it will redirect the command line to a 32bit command line which doesn't support defrag since it is only works in 64bit to avoid this you can run the 64bit command line by disabling the 32bit redirection. By doing so will allow you to only maintain one script instead of separate ones compiled for 32bit and 64bit. Here is a example below which tested successful both 32bit and 64bit:

;This disables the redirection to a 32bit command line

DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 0)

;This would be a command you would like to run as a 64bit application

RunWait(@ComSpec & ' /c defrag.exe -a ' & $DrivetoCheck & ' >>' & $TempFragmentationLog, @SystemDir, @SW_HIDE)

;This re-enables the redirection to a 32bit command line

DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 1)

;Output from defrag is different so you need to add a if statement to take this into consideration:

If @OSVersion = "WIN_7" Then

$retVal = StringSplit($Data, @CRLF)

$Fragit=StringSplit($retVal[29], "=")

$retVal=StringSplit($Fragit[2], "%")

$FragPercentage = StringStripWS($retVal[1],8)

Else

$retVal = StringSplit($Data, ",") ; Split data up into array using , as delimiter

$Fragit=$retVal[4] ; Element 4 is where the meat is. Lists frag levels

$retVal=StringSplit($Fragit, "%") ; Split it at % - Just grab Numeric

$FragPercentage = StringStripWS($retVal[1],8) ; Remove white Space

EndIf

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  
Followers 0