This VBScript illustrates how to automate the user's Out of Office state in Outlook.
Sometimes user will forget to turn on or turn off the Out of Office assistant, this could be annoying. Using this script will help user to manage his/her Out of Office state automatically.
Step1. Open the "CreateOOFScheduler.bat" file with Notepad.
The following command schedules a task named "OOFStartTime" to run at 12:00:00 from Monday to Friday of every week. It uses the /d parameter to specify the days.
schtasks /create /tn OOFStartTime /tr "cscript //nologo D:\OOF.vbs True" /sc weekly /d MON,TUE,WED,THU,FRI /st 12:00:00
The following command schedules a task named "OOFEndTime"to run at 12:30:00 from Monday to Friday of every week. It uses the /d parameter to specify the days.
schtasks /create /tn OOFEndTime /tr "cscript //nologo D:\OOF.vbs False" /sc weekly /d MON,TUE,WED,THU,FRI /st 12:30:00
The days for the /d parameter can be these values:
SUN (Sunday)
MON (Monday)
TUE (Tuesday)
WED (Wednesday)
THU (Thursday)
FRI (Friday)
SAT (Saturday)
For more information about how to use the schtasks command, please refer to: Schtasks: Management Services
Step2.
Change the VBScript file path.
You can change the "D:\OOF.vbs" to where the VBScript file located.
The "True" argument for the "OOF.vbs" file is to turn on the Out of Office state while the "False" argument is to turn off the Out of Office state.
Step3. Change the time range.
You can change "12:00:00" and "12:30:00" to other time values.
Step4. Add multiple time ranges
Just repeat these two commands and make sure the task name is unique. Also modify the time ranges or other necessary arguments.
schtasks /create /tn OOFStartTime1 /tr "cscript //nologo D:\OOF.vbs True" /sc weekly /d MON,TUE,WED,THU,FRI /st 9:00:00
schtasks /create /tn OOFEndTime1 /tr "cscript //nologo D:\OOF.vbs False" /sc weekly /d MON,TUE,WED,THU,FRI /st 9:30:00
schtasks /create /tn OOFStartTime2 /tr "cscript //nologo D:\OOF.vbs True" /sc weekly /d MON,TUE,WED,THU,FRI /st 12:00:00
schtasks /create /tn OOFEndTime2 /tr "cscript //nologo D:\OOF.vbs False" /sc weekly /d MON,TUE,WED,THU,FRI /st 12:30:00
schtasks /create /tn OOFStartTime3 /tr "cscript //nologo D:\OOF.vbs True" /sc weekly /d MON,TUE,WED,THU,FRI /st 14:00:00
schtasks /create /tn OOFEndTime3 /tr "cscript //nologo D:\OOF.vbs False" /sc weekly /d MON,TUE,WED,THU,FRI /st 15:00:00
...
Or you can schedule a task by either creating a basic task using the Create Basic Task Wizard or by creating a task without the wizard and supplying task information in the Create Task dialog box. For more information about how to schedule a task in Task Scheduler (Control Panel >> System and Security >> Administrative Tools >> Task Scheduler), please refer to: Schedule a Task
Step5. Delete all the added tasks using the "DeleteOOFScheduler.bat" file.
Open this batch file with Notepad and then check if these two tasks (OOFStartTime & OOFEndTime) were added in the Task Scheduler.
The following command deletes the OOFStartTime task and the OOFEndTime task from the schedule of the local computer, including tasks scheduled by other users. It uses the /f parameter to suppress the confirmation message.
schtasks /delete /tn OOFStartTime /f
schtasks /delete /tn OOFEndTime /f
If you have multiple tasks to delete, please repeat the command and then change the TASKNAME which exists in the Task Scheduler, or you can delete them from Task Scheduler manually.
schtasks /delete /tn TASKNAME /f
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
' ###############################
' Toggle the Out of Office state.
' ###############################
Public Sub ToggleOOFState(Byval OOFState)
Dim olApp
Dim blnIsCreated
Dim blnOOFState
Dim stoItem
Dim stoItems
Dim olPropAccessor
On Error Resume Next
If SingleInstanceModeForAutomationObject(olApp, blnIsCreated, "Outlook.Application") = True Then
' The name of the property whose value is to be returned.
Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B"
' Set reference to the Stores collection.
Set stoItems = olApp.GetNamespace("MAPI").Stores
' /* Step through each store object in the stores collection. */
For Each stoItem In stoItems
' /* a primary Exchange mailbox store. */
If stoItem.ExchangeStoreType = olPrimaryExchangeMailbox Then
'Obtain an instance of PropertyAccessor class.
Set olPropAccessor = stoItem.PropertyAccessor
' Get the Out of Office state.
blnOOFState = olPropAccessor.GetProperty(PR_OOF_STATE)
' /* Toggle the Out of Office state if the old state is not the same as the given state. */
If blnOOFState <> OOFState Then Call olPropAccessor.SetProperty(PR_OOF_STATE, OOFState)
End If
Next
End If
If blnIsCreated = True Then olApp.Quit
' /* Release memory. */
Set olApp = Nothing
Set stoItem = Nothing
Set stoItems = Nothing
Set olPropAccessor = Nothing
End Sub
' ############################### ' Toggle the Out of Office state. ' ############################### Public Sub ToggleOOFState(Byval OOFState) Dim olApp Dim blnIsCreated Dim blnOOFState Dim stoItem Dim stoItems Dim olPropAccessor On Error Resume Next If SingleInstanceModeForAutomationObject(olApp, blnIsCreated, "Outlook.Application") = True Then ' The name of the property whose value is to be returned. Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B" ' Set reference to the Stores collection. Set stoItems = olApp.GetNamespace("MAPI").Stores ' /* Step through each store object in the stores collection. */ For Each stoItem In stoItems ' /* a primary Exchange mailbox store. */ If stoItem.ExchangeStoreType = olPrimaryExchangeMailbox Then 'Obtain an instance of PropertyAccessor class. Set olPropAccessor = stoItem.PropertyAccessor ' Get the Out of Office state. blnOOFState = olPropAccessor.GetProperty(PR_OOF_STATE) ' /* Toggle the Out of Office state if the old state is not the same as the given state. */ If blnOOFState <> OOFState Then Call olPropAccessor.SetProperty(PR_OOF_STATE, OOFState) End If Next End If If blnIsCreated = True Then olApp.Quit ' /* Release memory. */ Set olApp = Nothing Set stoItem = Nothing Set stoItems = Nothing Set olPropAccessor = Nothing End Sub
Note:
1. When executing the "CreateOOFScheduler.bat" file, you may need to type the run as password in the command line window.
2. The Microsoft Outlook dialog box might display while the task is executing, please do the following steps to avoid it:

For Outlook 2007:
Tools >> TrustCenter... >> Programmatic Access >> Never warn me about suspicious activity (not recommended) >> OK >> Restart Outlook
For Outlook 2010:
File >> Options >> Trust Center >> Trust Center Settings... >> Programmatic Access >> Never warn me about suspicious activity (not recommended) >> OK >> OK >> Restart Outlook
3. This script can be run on Outlook 2007 and 2010. It requires that your e-mail account type is an Exchange store type.
Store.PropertyAccessor Property (Outlook)
PropertyAccessor.GetProperty Method
PropertyAccessor.SetProperty Method
Related forum threads
http://social.technet.microsoft.com/Forums/en-US/outlook/thread/5908031e-e7d4-4800-ac6f-c49d374b4d8b