Click to Rate and Give Feedback
MSDN
MSDN Library
WMI Reference
WMI Classes
Win32 Classes
Win32_Volume
 Chkdsk Method of the Win32_Volume C...
Chkdsk Method of the Win32_Volume Class

The Chkdsk method invokes the Chkdsk operation on the volume. The method is only applicable to volume instances that represent a physical disk on the computer. It is not applicable to mapped logical drives.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

MOF
uint32 Chkdsk(
  [in]  boolean FixErrors = FALSE,
  [in]  boolean VigorousIndexCheck = TRUE,
  [in]  boolean SkipFolderCycle = TRUE,
  [in]  boolean ForceDismount = FALSE,
  [in]  boolean RecoverBadSectors = FALSE,
  [in]  boolean OkToRunAtBootUp = FALSE
);

Parameters

FixErrors [in]

If true, errors found on the disk are fixed. The default is false.

VigorousIndexCheck [in]

If true, a vigorous check of index entries is performed. The default is true.

SkipFolderCycle [in]

If true, the folder cycle checking should be skipped. The default is true.

ForceDismount [in]

If true, the volume is dismounted before checking. The default is false.

RecoverBadSectors [in]

If true, the bad sectors are located and the readable information is recovered. The default is false.

OkToRunAtBootUp [in]

If true, the Chkdsk operation is performed at the next boot up, in case the Chkdsk operation could not be performed because the volume was locked at the time the method was called. The default is false.

Return Value

Returns one of the following numeric values.

Return codeDescription
0

Success

1

Success - Volume Locked and Chkdsk Scheduled on Reboot

2

Unsupported File System

3

Unknown File System

4

No Media In Drive

5

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 clientNone supported
Minimum supported serverWindows Server 2003
MOFVds.mof
DLLVdswmi.dll
Namespace\root\cimv2

See Also

Win32_Volume

Send comments about this topic to Microsoft

Build date: 11/3/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Win32_Volulme Chkdsk method - sample using PowerShell      Thomas Lee ... boofy24   |   Edit   |   Show History
# wmi-chkdsk.ps1
# Runs chkdsk to checks a local hard disk.
# Script just checks C:\
# thomas lee - tfl@psp.co.uk
# Helper function to Decode Return Code
function Get-DfragReturn {
param ([uint16] $char)
# parse and return values
If ($char -ge 0 -and $char -le 5) {
  switch ($char) {
0 {"00-Success"}
1 {"01-sUCCESS (volume locked and chkdsk scheduled for reboot"}
2 {"02-unsupported file system"}
3 {"03-Unknown file system"}
4 {"04-No Media in drive"}
5 {"05-Unknown Error"}
}
}
Else {
"{0} - *Invalid Result Code*" -f $char}
Return
}
  
# Get all local disks
# then get first drive (C:\)
$disks=gwmi win32_Volume
$c=$disks | where {$_.name -eq "C:\"}
# print start
"Checking {0} on system: {1}" -f $c.name,$c.SystemName
# Now specify chkdsk paramaters and call chkdsk
$FixErrors          = $false    # does not fix errors 
$VigorousIndexCheck = $true # performs a vigorous check of the indexes
$SkipFolderCycle = $false # does not skip folder cycle checking.
$ForceDismount = $false # will not force a dismount (to enable errors to be fixed)
$RecoverBadSecors = $false # does not recover bad sectors
$OKToRunAtBootup = $false # runs now, vs at next bootup
$start=get-date
"Commencing Defrag"
$res=$c.chkdsk($FixErrors,
$VigorousIndexCheck,
$SkipFolderCycle,
$ForceDismount,
$RecoverBadSecors,
$OKToRunAtBootup)
$finish=get-date
# Now Display returndvalue 
"Chkdsk call returned: {0}" -f (Get-DfragReturn($res.ReturnValue))
# Finally print time elapsed
"Starting Check Disk at: {0}" -f $start
"Finished at {0}" -f $finish
$duration = $finish-$start
"Elapsed time {0} minutes" -f ($duration.totalminutes.tostring("0.00"))

This script when run on a Longhorn Beta 2 system produces the followign output:

PS C:\Users\Administrator> .\wmi-chkdsk.ps1
Checking C:\ on system: LHS1
Commencing Defrag
Chkdsk call returned: 00-Success
Starting Check Disk at: 16/06/2007 16:45:55
Finished at 16/06/2007 16:50:31
Elapsed time 4.59 minutes
PS C:\Users\Administrator>
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker