Defrag in shutdown script for clients

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
FreakElectrique
Posts: 1
Joined: 02 Sep 2010 03:12

Defrag in shutdown script for clients

#1 Post by FreakElectrique » 02 Sep 2010 04:11

Hey y'all

I want to improve the defrag code in our shutdown script.
This shutdown script runs as clients shutdown their pc.
The defrag piece of the shutdown batchscript is going to defrag their hd.
I think that it is not necessary that the clients defrag each time as they shut down.
So I only want to defrag if the defrag <volume> -a --> analyse says it's needed.
How do I check this.
Well I send the output of defrag c:\ -a --> to c:\temp\defrag.txt
And then I search if it can find the word not.
See report.

Code: Select all

Windows Disk Defragmenter
Copyright (c) 2001 Microsoft Corp. and Executive Software International, Inc.

Analysis Report                      
    30,01 GB Total,  2,27 GB (7%) Free,  9% Fragmented (16% file fragmentation)

You do not need to defragment this volume.    

Here is the code.

Code: Select all

echo ************************************
echo *      start defragmenting       *
echo ************************************

date /t  >> %AU_dir%\logs\shutd_%COMPUTERNAME%.log
time /t  >> %AU_dir%\logs\shutd_%COMPUTERNAME%.log
if "%main_drive%" == "C" goto defrag_xp

:defrag_xp
ver | find "Version 6.1" > nul
if %ERRORLEVEL% == 0 goto win7

::Analyse Defrag
defrag c: -a > c:\temp\defrag.txt

findstr /m "not" c:\temp\defrag.txt
if %errorlevel%==0 (
echo Deze pc moet niet gedefragmenteerd worden!
if exist "c:\temp\defrag.txt" del /s/Q "c:\temp\defrag.txt"
goto verder2
)

c:\etc\bin\autodefrag -d >> %AU_dir%\logs\shutd_%COMPUTERNAME%.log
goto verder2

:win7
C:\Windows\system32\defrag /C /H /U /V /X >> %AU_dir%\logs\shutd_%COMPUTERNAME%.log

:verder2
echo ************************************
echo *      end defragmenting       *
echo ************************************


Now I also want to do this for the win7 clients.
Defrag on win7 is a bit different.
For one you won't see a gui and the report of the analysis is a bit different.

Now here is my question.
Is there a way to show the user a defraggui?
If not I want to show the user some kind of progress bar dots .... or better a slash that go's round (-- \ | / -- \ | / --) while the client is defragging.

And also
For win7 I want to do a search the word "'need" because the report for win7 defrag is a bit different.
I think this will work or does somebody knows a better way to check if the pc needs a defrag or not.

Thx in advance

Post Reply