Recipe 7.10. Checking a Volume for Errors


Problem

You want to check a volume for errors.

Solution

Using a graphical user interface

  1. Open Windows Explorer.

  2. Right-click the drive you want to defragment and select Properties.

  3. Click the Tools tab.

  4. Under Error-checking, click the Check Now button.

  5. If you want any filesystem errors that are found to be fixed, check the box beside Automatically fix filesystem errors. If you want to perform a thorough scan of the disk and check for bad sectors, check the box beside Scan for an attempt recovery of bad sectors.

  6. Check the disk options you want and click Start.

  7. Click OK when the check completes.

Using a command-line interface

The 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

Discussion

Running 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"



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net