Solved

Running defrag

Posted on 2004-08-01
4
302 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 149
ORA-01403: no data found 43 90
Named range not carried over 10 62
WinWaitActive parameters 12 31
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

13 Experts available now in Live!

Get 1:1 Help Now