The Defrag method defragments the volume.
This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see
Calling a Method. The Defrag method, like the Format method, can run for a very long time. These methods are normally called asynchronously. If your code cancels the call by calling IWbemServices::CancelAsyncCall (or SWbemSink.Cancel in script or Visual Basic), then the provider is not notified and the operation continues to completion. During this time, no other disk defragmentation operations can be performed, because only one instance of a defragmentation engine can run at a time.
Syntax
uint32 Defrag(
[in] boolean Force,
[out] object DefragAnalysis
);
Parameters
- Force [in]
-
If true, forces defragmenting of the volume even if free space is low. The default is false.
- DefragAnalysis [out]
-
A Win32_DefragAnalysis object that contains the properties that describe the extent to which the volume is fragmented.
Return Value
Returns one of the following numeric values.
| Return code | Description |
- 0
| Success
|
- 1
| Access Denied
|
- 2
| Not Supported
|
- 3
| Volume Dirty Bit Is Set
|
- 4
| Not Enough Free Space
|
- 5
| Corrupt Master File Table Detected
|
- 6
| Call Canceled
|
- 7
| Call Cancellation Request Too Late
|
- 8
| Defrag Engine Is Already Running
|
- 9
| Unable To Connect To Defrag Engine
|
- 10
| Defrag Engine Error
|
- 11
| Unknown Error
|
Examples
For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.
For C++ code examples, see WMI C++ Application Examples.
Requirements
| Minimum supported client | None supported |
| Minimum supported server | Windows Server 2003 |
| MOF | Vds.mof |
| DLL | Vdswmi.dll |
| Namespace | \root\cimv2 |
See Also
- Win32_Volume
Send comments about this topic to Microsoft
Build date: 11/3/2009