Solved

Running defrag

Posted on 2004-08-01
4
301 Views
Last Modified: 2013-11-20
How can I run a Windows built-in disk defragmenter from my MFC app?

My app creates/deletes large numbers of large files, soI would like it to automatically defragment the hard drive, when it finds appropriate. The defrag should run with no user assistance.
0
Comment
Question by:olegsp
4 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 60 total points
Comment Utility
You can use WinApi WinExec funtion to call defrag.exe:

::WinExec("defrag c:", SW_HIDE);

Also you can use WinAPI ShellExecute() function.
0
 
LVL 14

Assisted Solution

by:wayside
wayside earned 40 total points
Comment Utility
You could use the file system control commands to write your own simple defragger as outlined here with source code: http://www.sysinternals.com/ntw2k/info/defrag.shtml

Or you could use WMI, using the Win32_Volume object and the DefragAnalysis and Defrag methods and the Win32_DefragAnalysis object to determine if you need to defragment, and then actually do it.

Defragging can take hours and significantly impacts the performance of the system when it runs,  I'm not sure it's such a good idea to do this automatically, unless the user has requested that it be done that way.
0
 

Assisted Solution

by:cheapstr
cheapstr earned 25 total points
Comment Utility
WinExec("c:\\windows\\system32\\dfrg.msc", SW_MAXIMIZE); should bring up the defrag program for you
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now