Check a Volume for errors (Perl)

This code can be found in Chapter 7 of Windows XP Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# From the book, "Windows XP Cookbook"
# ISBN: 0596007256

# ------ SCRIPT CONFIGURATION ------

use Win32::OLE;

$strComputer = '.';
$strDrive = '<Drive>';
# e.g. D:
$boolFixErrors = 1;
# True = chkdsk /f, False = chkdsk
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$objDisk = $objWMI->Get('Win32_LogicalDisk.DeviceID=\'' . $strDrive . '\'');
$intRC = $objDisk->ChkDsk($boolFixErrors);
if ($intRC == 0) {
    print "Chkdsk completed successfully.\n";
}
elsif ($intRC == 1) {
    print "Chkdsk scheduled on next reboot.\n";
}
else {
    print 'Error running chkdsk: ' . $intRC, "\n";
}

This code has been viewed 878 times.

New from the creators of TechTasks.com: StatSheet.com