Preventing users from accessing DB while indexes are being rebuilt
USE master;
GO
ALTER DATABASE YourDatabase 
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
USE YourDatabase;
--Run index maint scripts...
GO
ALTER DATABASE YourDatabase
SET MULTI_USER;
GO