Here is a more sophisticated script:
PHP Code:
<?php
@ini_set('display_errors', 0);
@error_reporting(0);
define('VB_AREA', 'Maintenance');
define('SKIP_SESSIONCREATE', 1);
define('SKIP_LOCATIONUPDATE', 1);
define('SKIP_DEFAULTDATASTORE', 1);
define('DISABLE_HOOKS', 1); // You might want to comment this out if you need plugins in this script
define('NOCOOKIES', 1);
define('CWD', '/path/to/vbulletin');
require(CWD . '/includes/init.php');
require(DIR . '/includes/adminfunctions.php');
$db->query_write("UPDATE " . TABLE_PREFIX . "setting SET value = " . (($_SERVER['argv'][1] == 1) ? 1 : 0) . " WHERE varname = 'bbactive'");
build_options();
?>
I've turned off all error reporting as vB 4 seems to assume that every request comes through a webserver

(Adding yet-another bug report now ...)
Also setting the board offline does not completely kill queries so you might still run into table locking issues.