Outlook 自动配置脚本

     目前有这样一个客户需求:在一期项目当中,客户端不加入域,但要求配置并使用客户端的Outlook。由于客户端数量较大(大约1200个),手工配置太繁琐,工作量也非常巨大,因此写了一个Outlook客户端配置脚本,顺便提供大家一个参考。

1、我们需要有一个Outlook配置文件(PRF文件),此配置文件的生成及具体参数请参考http://technet.microsoft.com/zh-cn/library/cc179062(TechNet.10).aspx

2、执行写好的脚本将配置文件导入并配置Outlook客户端即可(PRF配置文件需要与脚本在同一目录,并在脚本中指定PRF文件的名称)

3、脚本内容


'===================================================================
'
' VBScript Source File  
'
' NAME: Billy Fu
'
' AUTHOR: Outlook配置脚本-Outlook_Profile_Config
'
' DATE  : 2008/7/14
'
'
'===================================================================
ON ERROR RESUME NEXT

Const OFFICE11_PATH = "C:\Program Files\Microsoft Office\Office11"
Const OFFICE12_PATH = "C:\Program Files\Microsoft Office\Office12"

dim strUserName
dim intOfficeVer
dim strOfficePath

strUserName = ""
intOfficeVer = ""
strOfficePath = ""

strUserName = InputBox("请输入您在域中的用户帐号,格式如:BillyFu","Outlook配置脚本")  
If strUserName = "" Then
    Msgbox "取消Outlook配置!"
Else
    while intOfficeVer = ""
  intOfficeVer = InputBox("请输入您本机安装的Outlook版本号:2007或2003,其他版本不支持","Outlook配置脚本","2003")  
  if intOfficeVer = "" then
      Msgbox "Outlook 设置取消!"
      intOfficeVer = "error"
  else
      if intOfficeVer <> "2007" And intOfficeVer <> "2003" Then
    intOfficeVer = ""
      else
    if intOfficeVer = "2007" then
        strOfficePath = OFFICE12_PATH
    else
        strOfficePath = OFFICE11_PATH
    end if
    strOfficePath = InputBox("请确定您本机安装的Outlook路径","Outlook配置脚本",strOfficePath)  
    Call InstallOutlookProfile
      end if
  end if  
    Wend
End If


sub InstallOutlookProfile


    ModifyPRFFile

    Dim WshShell
    Set WshShell = Wscript.CreateObject("Wscript.Shell")
  

    Dim strPath
    strPath = WScript.ScriptFullName  
    strPath = Left(strPath, InstrRev(strPath, "\")) & "OutlookProfile1.PRF" '指定Outlook PRF 配置文件
  
    dim strCmd
    strCmd = """" & strOfficePath & "\outlook.exe"" /importprf """ & strPath & """"  
    WshShell.Run strCmd, 1, false
end sub

sub ModifyPRFFile

   Const ForReading = 1, ForWriting = 2, ForAppending = 8
   Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
   Dim strCon


   Dim fso, f1, f2, ts
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f1 = fso.GetFile("OutlookProfile.PRF") '设置从Outlook配置文件中读取信息
   Set ts = f1.OpenAsTextStream(ForReading, TristateUseDefault)
   strCon = ts.ReadAll
   ts.close

   strCon = Replace(strCon,"%UserName%",strUserName)


   fso.CreateTextFile "OutlookProfile1.PRF"  
   Set f2 = fso.GetFile("OutlookProfile1.PRF") '创建一个配置文件
   Set ts = f2.OpenAsTextStream(ForWriting, TristateUseDefault)
   ts.Write strCon
   ts.Close

end sub

sub Err

   if err <> 0 then
      Wscript.echo "Outlook配置脚本出错,自动退出!"
      Err.Clear
   end if

end sub

 

分享到