Defragment all disk using auslogics defragmentation tool

Hi all,

Please use below procedure to defragment all partitions,

Major steps by procedures:

  1. Download auslogics defragmentation tool
  2. Install the tool
  3. Trigger defragmentation of using auslogics command line utility (cdefrag.exe)
  4. Uninstall the tool

Note:

  1. Run the script as “system user”
  2. No input requires

import os
import urllib
import subprocess 


global temp
temp=os.environ['TEMP']
url='http://static.auslogics.com/en/disk-defrag/disk-defrag-setup.exe'

def downloadFile(DownTo, fromURL):
    try:
        fileName = fromURL.split('/')[-1]
        DownTo = os.path.join(DownTo, fileName)        
        with open(DownTo, 'wb') as f:
            f.write(urllib.urlopen(fromURL).read())
        if os.path.isfile(DownTo):
            return '{} - {}KB'.format(DownTo, os.path.getsize(DownTo)/1000)
    except:
        return 'Please Check URL or Download Path!'

def install():
    import subprocess
    sp = subprocess.Popen(temp+r'\disk-defrag-setup.exe  /SP- /SUPPRESSMSGBOXES /VERYSILENT', stdout=subprocess.PIPE)
    out,err = sp.communicate()
    rc = sp.returncode
    if rc==0:
        print out
        print 'Auslogics defragmentation has been installed successfully '
    else:
        print err
    return()


def  run(path):
    os.chdir(path)
    code={0:'Success',1:'Error defragmenting one or more disks.',2:'Administrator access rights are required to defragment disks.',3:'The command line parameters are invalid.',4:'Defragmentation was cancelled by user.',5:'Unsupported Windows version.',6:'Error creating log file.',7:'Another instance is already running.',8:'Low free space on the disk.',9:'The computer has been turned off or rebooted.'}
    defrag = subprocess.Popen('cdefrag.exe -c -f', stdout=subprocess.PIPE)
    out,err = defrag.communicate()
    rc = defrag.returncode
    if rc==0:
        print out
        print 'Auslogics  completed defragmentation process '
    else:
        print err
        print code[rc]    
    os.chdir(temp)
    return()

def uninstall(path):
    os.chdir(path)
    remove= subprocess.Popen('unins000.exe /VERYSILENT /SUPPRESSMSGBOXES', stdout=subprocess.PIPE)
    out,err = remove.communicate()
    rc = remove.returncode
    if rc==0:
        print out
        print 'Auslogics defragmentation has been uninstalled successfully '
    else:
        print err
        print 'Auslogics defragmentation  uninstallation has been failed'
    os.chdir(temp)
    return()


print downloadFile(temp,url)

if 'PROGRAMW6432' in os.environ.keys():
        command_path=r'C:\Program Files (x86)\Auslogics\Disk Defrag'
        uninstall_path= r'C:\Program Files (x86)\Auslogics\Disk Defrag'
else:
        command_path='C:\Program Files\Auslogics\Disk Defrag'
        uninstall_path=r'C:\Program Files\Auslogics\Disk Defrag'



install()
run(command_path)
uninstall(uninstall_path)
os.chdir(temp)
os.remove('disk-defrag-setup.exe')


20170408-Defragment-disks-using-auslogics-defragmentation-tool.json (3.93 KB)

sample output

I’m not quite sure what is going on, but this is the message that I received:
C:\WINDOWS\TEMP\disk-defrag-setup.exe - 7910KB None None Another instance is already running. Auslogics defragmentation has been uninstalled successfully

Hmmmm… It looks like I had to uninstall Auslogics defrag and reboot the endpoint in order for it to work… But it looks like it may have actually run.

One issue I see with any script that runs 3rd party defrag systems, is that they do not see the shadow volumes, and writes right over the restore points. This may not be the case with Auslogic Defragmentor, This may not be an issue all the time, but I have ran into it being an issue for me a time or two. So I just wanted ensure people know that this may be possible, again I am not sure if this program will over write the restore points or not, as I don’t use this one.

Thank you for the heads up @BOSS!

After testing a wee bit more, it seems that you can’t have Auslogics defrag installed and run this script. At least, that’s the way it has / hasn’t been working for me. Once I uninstalled it on a few endpoints and tried running this same script again, it seems to work.

You’re welcome, I just don’t want anyone to have to find out the hard way.

Does the script uninstall the application after it is done??

Hi @BOSS

I have defined functions to uninstall Auslogic in the script. For your information.

Thanks

@BOSS The script does seem to uninstall the application after it’s done. The issue I was running into was that I had Auslogics defrag installed on a lot of the endpoints already. Thus, I think that was causing issues with running it via ITSM.

Also, @mkannan, do you know what the fragmentation threshold is, in order for the process to actually defragment the drives? For example, does the fragmentation level of a drive have to be 3% before it will actually be defragmented via Auslogics.

Thank you again in advance!

Thanks, that’s good to know, that’s how I prefer it work.

I see, thanks for the heads up, did you get a chance to see if it over wrote restore points??

@mkannan @BOSS
Hi
​​​​​​​i found that it run successfully on windows 7 and 8 but it fails on all windows 10 devices
please see the attachment
Thanks ​​​​​​​

Hi @aghiad

please refer the below link :
https://scripts.comodo.com/frontend/web/topic/defragment-all-disk-using-defraggler-defragmentation-tool

Thanks

@Tamilselvam
Hi thanks for your advice
i tried but on some devices i never get the result back (Not All devices ) , nothing show up in Script Log in this case i do not know if the script fails or success
any idea ?

Thanks

Hi @aghiad

we will check and update you as soon.

Thanks

Hi @aghiad

We checked the below script in different Platforms, which is working fine.

So please crosscheck and revert us with your feedbacks.

https://scripts.comodo.com/frontend/web/topic/defragment-all-disk-using-defraggler-defragmentation-tool

Note:

1)This script should run as System User.
2)Defragmentation process script logs should takes some more time to generate.

Thank You

@santhosh @sathish
Hi i got this error in some devices
​​​​​​​Thanks

Hi @aghiad

We will check this error and update you soon.

Thank You

Hi @aghiad

The script which we have already provided to you is perfectly working for us.
There seems to be an issue with the proxy option.The script usually works without the proxy option if have any proxy setting remove and try the script.

Refer the following script link
https://scripts.comodo.com/frontend/web/topic/defragment-all-disk-using-defraggler-defragmentation-tool

Thank you
Tamilselvam