ProblemYou want to check a volume for errors. SolutionUsing a graphical user interface
Using a command-line interfaceThe chkdsk utility can detect problems with a volume and attempt to fix them. Specify the name of the volume you want to check to run chkdsk in read-only mode: > chkdsk D: Use the /f option to have chkdsk attempt to fix any errors it finds: > chkdsk D: /f With the /f option, chkdsk will try to lock the drive, so if it is in use by another process, you will only be able to schedule it to run during the next reboot. You can include the /x option with /f to force the volume to be dismounted (for a nonsystem volume). Using VBScript' This code tries to perform a chkdsk on the specified volume. ' ------ SCRIPT CONFIGURATION ------ strComputer = "." strDrive = "<Drive>" ' e.g. D: boolFixErrors = True ' True = chkdsk /f, False = chkdsk ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objDisk = objWMI.Get("Win32_LogicalDisk.DeviceID='" & strDrive & "'") intRC = objDisk.ChkDsk(boolFixErrors) if intRC = 0 then WScript.Echo "Chkdsk completed successfully." elseif intRC = 1 then WScript.Echo "Chkdsk scheduled on next reboot." else WScript.Echo "Error running chkdsk: " & intRC end if DiscussionRunning chkdsk on an active volume it may report transient errors that are due to the volume being in use. If you see any errors at all, you should run chkdsk /f to schedule the errors to be examined and fixed after the next reboot. See Also"Chkdsk Method of the Win32_LogicalDisk Class," MS KB 160963, "CHKNTFS.EXE: What You Can Use It For," MS KB 187941, "An explanation of CHKDSK and the new /C and /I switches," MS KB 191603, "Modifying the Autochk.exe Time-out Value," and MS KB 218461, "Description of Enhanced Chkdsk, Autochk, and Chkntfs Tools in Windows 2000" |