Solved

Running defrag

Posted on 2004-08-01
4
305 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
ID: 11690684
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
ID: 11695911
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
ID: 11969342
WinExec("c:\\windows\\system32\\dfrg.msc", SW_MAXIMIZE); should bring up the defrag program for you
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 52
Separate files macro - Errors on larger data set 18 73
Define unique primary key 9 95
twoTwo  challenge 35 107
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

792 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