check windows defrag analysis

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
menno
Posts: 158
Joined: Fri May 21, 2010 1:27 am

check windows defrag analysis

Post by menno »

Hello all

i want to make a check that checks the output of the dos-box command.
i want to check , and HM reply , the last line from the defrag command.
Here is the example from the dos-box :

Code: Select all

C:\Users\Administrator>defrag c: /a
Microsoft Drive Optimizer
Copyright (c) 2013 Microsoft Corp.

Invoking analysis on (C:)...

The operation completed successfully.

Post Defragmentation Report:

        Volume Information:
                Volume size                 = 49,99 GB
                Free space                  = 37,35 GB
                Total fragmented space      = 30%
                Largest free space size     = 30,66 GB

        Note: File fragments larger than 64MB are not included in the fragmentation statistics.

       It is recommended that you defragment this volume.
is it possible to get this line in the Reply field of HM ?
It is recommended that you defragment this volume.
or better
Total fragmented space = 30%
and then in this case 30%

I allready played with some scripts but i did not find the solution.
Can you please help me ?
Many many thanks in advance

M
Last edited by menno on Thu Jan 28, 2016 5:34 am, edited 2 times in total.
SplanK
Posts: 38
Joined: Wed Nov 21, 2007 1:33 pm

Post by SplanK »

You could make a VBS script which captures the output of the text, loops through it and processes it.


The below (bit messy sorry) example is an example of looking through the output of Ipconfig and sets a variable to 1 if it finds "192.168." within the output.

Code: Select all

set WSHShell = WScript.CreateObject("WScript.Shell") 

Set oExec = WshShell.Exec("cmd /c ipconfig")

Do until oExec.Stdout.atEndOfStream
	oReadLine = oExec.StdOut.ReadLine
	If instr(oReadLine, "192.168.") > 0 Then 
		oNetExtenderFound = 1
	End If
Loop

wscript.echo oNetExtenderFound
menno
Posts: 158
Joined: Fri May 21, 2010 1:27 am

Post by menno »

thanks splank but this not what i want

if i do a : defrag c: /a in the output there is (as example) :

Total fragmented space = 24%

I just want somthing like :
if "fragmented space" is greater than xx% then test is BAD
or just only the "fragmented space" in the Reply field

can someone ( most of the time Alex ) make this happen for me ?

many thanks in advance
menno
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

You may use the following JS script with Shell Script test method:

Code: Select all

// Script requires 0,1 or 2 parameters: [disk letter [max defreg threshold]]
statusUnknown     = "scriptRes:Unknown:";
statusOk          = "scriptRes:Ok:";
statusBad         = "scriptRes:Bad:";

objArgs = WScript.Arguments;

var max = 101;
var hdd = 'c';

if (objArgs.length==1) {
  hdd = objArgs(0);
}
if (objArgs.length>1) {
  hdd = objArgs(0);
  max = parseInt(objArgs(1));
}

try {
var WshShell = new ActiveXObject("WScript.Shell");
var cmd = WshShell.Exec('cmd /c defrag '+hdd+': /a');

while (cmd.Status === 0) {
    WScript.Sleep(100);
}
var output = cmd.StdOut.ReadAll();

} catch(e) {
  WScript.StdOut.Write(statusUnknown + e.Message);
  WScript.Quit();
}

if (output.indexOf('Total fragmented space')==-1) {
  WScript.StdOut.Write(statusUnknown + "Incorrect output.");
  WScript.Quit();
}

if (max==101) {
 if (output.indexOf("recommended that you defragment")>-1) {
  max = 0;
 }
}

output=output.substr(output.indexOf("Total fragmented space"));
output=output.substr(output.indexOf("="));
output=output.substr(1,output.indexOf("%")-1);
output=output.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); // trim()

var val = parseInt(output);

if (val>max) {
  WScript.StdOut.Write(statusBad + val + " %");
} else {
  WScript.StdOut.Write(statusOk + val + " %");
}
start CMD on 64-bit OS: C:\Windows\sysnative\cmd /c cscript /B /E:JScript %Script% %Params%
start CMD on 32-bit OS: cmd /c cscript /B /E:JScript %Script% %Params%

Script requires 0, 1 or 2 parameters: [disk letter [max defreg threshold]]
Several examples:
<no parameters specified> - script will check fragmentation of c drive
d - script will sheck fragmentation % of drive d
c 11 - script will check drive c for fragmentation percent and set Bad status if fregmented space is more than 11 % (script will ignore defrag recommendation)
menno
Posts: 158
Joined: Fri May 21, 2010 1:27 am

Post by menno »

thanks this works fine !

menno
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

You are welcome!
Post Reply