OOF 自动化
自动设置外出助手
引言
OOF(离开办公室)自动化是一个基于 VBScript 的自动化程序,当相应用户输入“外出”约会时,它会自动打开 OOF 助理;当不再有“外出”约会时,它会自动关闭。
此程序通过使用任务计划程序(例如,每 30 分钟)外部使用 CDO 来实现。在CDOLive也可以找到内部解决方案。但是,我在实现它时遇到了 MAPI 问题,因为我的 Outlook OOF 消息突然与脚本中修改的消息不同步。
使用脚本
每个希望参与 OOF 助理自动切换的最终用户都必须在其 OOF 消息中设置至少一个(可配置的)占位符来代替最终消息中要显示的日期(例如,“我将于<Date>
离开办公室。如有紧急事项,请联系……- 此致,Roland”)。
<Date>
将被替换为 从 <开始日期/时间> 到 <结束日期/时间>
。从
和到
可以在脚本中配置为两种语言(目前为德语和英语)。相应的占位符是<Datum>
和<Date>
。
完成此操作后,所有最终用户需要做的就是将其缺勤输入为“外出”约会或全天事件。OOFAutomation 脚本将完全自动为他切换 OOF 助理。通过将日志记录到指定的 文件中(请参见下面的安装)来支持管理。
安装
安装方法是将两个脚本复制到 OOFAutomation 服务器可以访问的文件夹中。这可以是安装了 Outlook 或 Exchange Server 的任何台式电脑或服务器。我没有检查是否单独安装可用的 CDO 库 也足够,但根据 Microsoft 在下载页面上的声明,应该足够。
将脚本复制到目标文件夹后,在 OOFAutomation 服务器上创建一个计划任务来启动脚本,例如每 30 分钟启动一次。运行此任务的帐户需要在 Exchange 中具有管理员权限,或者至少对所有最终用户的 MAPI 存储具有访问权限。但是,在激活任务之前,必须配置这两个脚本。
OOFAutomation.vbs
'TO CONFIGURE: Change "ServerName" to the name of your Exchange Server
Const sServerName = "OEBFASRV02"
'TO CONFIGURE: Change "MailboxName" to the name
'of an administrative mailbox on the server specified above
Dim sProfileInfo ' the MAPI logon profile
sProfileInfo = sServerName & vbLf & "Administrator"
'TO CONFIGURE: Change placeholders and
'infixes to reflect your used languages
'(2 at most, if more are needed then change the code yourself...)
Const placeHolderLang1 = "<Datum>"
Const placeHolderLang2 = "<Date>"
Const infixFrom1 = "von "
Const infixFrom2 = "from "
Const infixTo1 = " bis "
Const infixTo2 = " to "
Const infixOn1 = "am "
Const infixOn2 = "on "
'TO CONFIGURE: Send Mails to these people in case of error.
Const ErrMailDistributionList = "rkapl"
Log.vbs
Log.vbs 是一个可单独使用的简单的Logger
类。它可以像这样在其他脚本中使用
Set WshShell = WScript.CreateObject("WScript.Shell")
ExecuteGlobal CreateObject(_
"Scripting.FileSystemObject").OpenTextFile("Log.vbs", 1).ReadAll
' PathToLogFolder.. (default = defaultLogPath in Log.vbs)
' NameOfLogFile.. (default = scriptname)
' maxLevelToBeLogged.. 0 = ERROR, _
' 1 = WARN, 2 = INFO, 3 = DEBUG (default)
' CommaSeparatedErrMailDistributionListString...
' e.g. "admin1, admin2, admin3" (default = defaultMailRecipients in Log.vbs)
' ErrMailSender.. (default = defaultMailSender in Log.vbs)
' ErrMailSubject.. (default = defaultMailSubject in Log.vbs)
Set theLogger = new_Logger(Array(PathToLogFolder,NameOfLogFile,_
maxLevelToBeLogged,CommaSeparatedErrMailDistributionListString, _
ErrMailSender,ErrMailSubject))
theLogger.LogInfo "Info Message"
theLogger.LogWarn "Warning Message"
theLogger.LogError "Error Message"
theLogger.LogStream (WshShell.Exec object)
'logs stderr output of Exec object as
'LogError messages, all other are logged as LogInfo
theLogger.LogFatal "Fatal Message (stops the script)"
但是,在使用前也需要对其进行配置
'TO CONFIGURE: Send Mails to these default
'people in case of error (if not set by using script).
Const defaultMailRecipients = "rkapl,any,other,person"
'TO CONFIGURE: The default sender of the error mails
Const defaultMailSender = "Administrator"
'TO CONFIGURE: The default subject of error mails
Const defaultMailSubject = "Process Error"
'TO CONFIGURE: The file, where internal errors are logged
Const internalLogFile = _
"\\path\to\your\internal\log\files\Log.vbs.internalErrs.log"
'TO CONFIGURE: The folder, where log files are being put
Const defaultLogPath = "\\path\to\your\Logs"
最后,激活任务,并在您的OOFMessage
文本中输入已配置的占位符进行测试。输入一个“外出”约会,该约会开始时间早于现在 -1 分钟,结束时间晚于现在 +1 分钟。
关注点
当然,使用的许多概念都来自CDOLive。
历史
- 2007 年 3 月 7 日:版本 1.0:发布 CodeProject 文章
- 2007 年 3 月 10 日:版本 1.1:修复了从 Outlook 更新 OOF 消息的错误。只要选择了“我目前在办公室”,并且消息中至少包含一个占位符(例如,
<Datum>
),现在就可以做到这一点。
新版本
为了从 Exchange 2010 开始自动化 OOF 设置,您可以使用 https://rkapl123.github.io/ExchangeSetOOF/ - 这使用了新的 EWS 协议(较新版本的 Exchange 服务器不支持 CDO)。