Enable disk quotas (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:
$intEnable = 2;
# 0 = Disabled, 1 = Tracked, 2 = Enforced
$intDefaultLimit = 1024 * 1024 * 500;
# 500 MB
$intDefaultWarning = 1024 * 1024 * 400;
# 400 MB
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$objDisk = $objWMI->Get('Win32_QuotaSetting.VolumePath=\'' . $strDrive . '\\\\\'');
$objDisk->{State} = $intEnable;
$objDisk->{ExceededNotification} = 1;
$objDisk->{WarningExceededNotification} = 1;
$objDisk->{DefaultLimit} = $intDefaultLimit;
$objDisk->{DefaultWarningLimit} = $intDefaultWarning;
$objDisk->PutWScript->Echo('Quotas enabled on ' . $objDisk->Caption);

This code has been viewed 663 times.

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