Environment: Windows XP, Outlook , EAS, vb-script
Description: This installs the EAS client for Outlook users in a given Active Directory OU, if they are a member of an EAS group. This script is run as Active Directory Group Policy log on script, and to make trouble shooting easier, all steps are written to application event log.
Code:
'=========================================================================
' VBScript Source File -- Created with XLnow OnScript
' FILE : UserOutlookEAS.vbs
' AUTHOR : Robert Lawson
' COMPANY: Soka University of America
' DATE : 6/19/2006 Robert Lawson Creation Date
' 11/20/2006 Robert Lawson Always do Outlook updates, improved on EAS logic
' 12/01/2006 Robert Lawson Added disable menu and remove pst references
' COMMENT: Manage EAS deployment: installing EAS client, and making Outlook setting
' conUpdateRegKeys controls if this will update registry keys (Outlook settings)
' Office 2003 only (Office Versions: 11.0 = 2003; 10.0 = XP)
' Registry keys are not setup by default by Outlook
'=========================================================================
option explicit
On Error Resume Next ' Required for reading registry
const conScriptName = "UserOutlookEAS.vbs"
const conDEBUG = FALSE
const conUpdateRegKeys = TRUE ' TRUE = will update Outlook reg keys
Dim strMsg, intLoc
Dim objShell, varTemp, bolRegKeyExists, varNewValue
Dim objFSO, objTS, objExecute
Dim bolOutlookInstalled, bolZantazClientInstalled, bolEASUser
Dim objNetwork, strUserName, strUserDomain, strGroupName, strComputerName
Dim strOU, strFilter, strQuery, rs, objCommand, UserADsPath, objUser, objConnection, objGroup, strKey
const conOutlookRegistryKey = "HKCU\Software\Microsoft\Office\11.0\Outlook\OutlookName"
const conOutlookDisableAutoArchiveKey = "HKCU\Software\Microsoft\Office\11.0\Outlook\Preferences\DoAging"
const conOutlookDisableCreatePSTfilesKey = "HKLM\SOFTWARE\Microsoft\Office\11.0\Outlook\DisablePST"
const conOutlookDisabledCmdBarKey = "HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\11.0\Outlook\DisabledCmdBarItemsList"
const conZantazFile = "C:\Program Files\ZANTAZ\EAS Client\EASCOMPRESS.dll"
const conEASclient = "\\server3\Client\uniClient.msi"
const conRegKeyYes = 1
const conEASGroup = "EASUser"
' Window stype to run
const WINDOWHIDDEN = 0
const WINDOWNORMAL = 1
const WINDOWMINIMIZE = 2
Const ADS_SCOPE_SUBTREE = 2
' ============================================================
' Setup
' ============================================================
Set objShell = CreateObject( "WScript.Shell" )
Set objNetwork = Wscript.CreateObject("Wscript.Network")
set objConnection=Createobject("ADODB.Connection")
set objCommand=CreateObject("ADODB.Command")
objConnection.Provider="ADSDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
strMsg = "BEGIN: " & conScriptName
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
' ============================================================
' Determine if EAS User (determined by AD group membership)?
' ============================================================
' Get User Info from Network log in
strComputerName = objNetwork.ComputerName
strUserName = objNetwork.UserName
strUserDomain = objNetwork.UserDomain
strMsg = conScriptName & " values: CN = " & strComputerName & "; UN = " & strUserName & "; DN = " & strUserDomain
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
' Get User Active Directory information
bolEASUser = FALSE
strOU = "DC=uni,DC=edu"
strFilter = "sAMAccountName = " & "'" & strUserName & "'"
strQuery = "SELECT ADsPath FROM 'LDAP://" & strOU & "' WHERE " & strFilter
strMsg = conScriptName & ": LDAP strQuery = " & strQuery
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
objCommand.CommandText= strQuery
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set rs = objCommand.Execute
if rs.EOF or rs.BOF then
intLoc = 5
strMsg = conScriptName & ": Error @ " & intLoc & ". Unabled to get AD user for " & strUserName
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
else
' Verify if user is member of an EAS group
UserADsPath = rs.fields("ADsPath").value
Set objUser = GetObject(UserADsPath)
For Each objGroup In objUser.Groups
' sample: "CN=grpPeopleSoftDBTech"
strGroupName = objGroup.Name
if conDEBUG then Wscript.Echo strGroupName
bolEASUser = (instr(1,strGroupName,conEASGroup) > 0)
if bolEASUser then Exit For
Next
end if
strMsg = conScriptName & ": bolEASUser = " & bolEASUser
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
' ============================================================
' Is Outlook installed for this computer user?
' ============================================================
varTemp = objShell.RegRead (conOutlookRegistryKey)
bolOutlookInstalled = (Err.number= 0)
if conDEBUG then Wscript.Echo " bolOutlookInstalled= " & bolOutlookInstalled
' ============================================================
' Is Zantaz EAS client installed on this computer? If not, do so
' ============================================================
set objFSO = CreateObject("Scripting.FileSystemObject")
bolZantazClientInstalled = (objFSO.FileExists(conZantazFile))
strMsg = conScriptName & ": bolOutlookInstalled = " & bolOutlookInstalled & "; conUpdateRegKeys = " & conUpdateRegKeys & _
"; bolZantazClientInstalled = " & bolZantazClientInstalled
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
' Need to install EAS client?
if bolOutlookInstalled and Not bolZantazClientInstalled then
set objFSO = CreateObject("Scripting.FileSystemObject")
if (objFSO.FileExists(conEASclient)) then
objShell.Run conEASclient, WINDOWHIDDEN, True
if err.number = 0 then
strMsg = conScriptName & ": Installed successfully " & conEASclient
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
bolZantazClientInstalled = TRUE
else
intLoc = 10
strMsg = conScriptName & ": Error @ " & intLoc & " Num = " & Err.number & " " & Err.Description
DoError(strMsg) ' Failed to execute
end if
else
intLoc = 15
strMsg = conScriptName & ": Error @ " & intLoc & ". File does not exist " & conEASclient
DoError(strMsg) ' File does not exist
end if
end if
' ============================================================
' Update Outlook Registry Entries?
' ============================================================
if bolOutlookInstalled and conUpdateRegKeys then
' Disable auto archive features? 1=yes, 0=no (if no registry, treated as = 0)
varTemp = ""
varTemp = obJShell.RegRead(conOutlookDisableAutoArchiveKey)
bolRegKeyExists = (err.number = 0)
err.Clear
if Not bolRegKeyExists or (varTemp <> conRegKeyYes) then
objShell.RegWrite conOutlookDisableAutoArchiveKey, conRegKeyYes, "REG_DWORD"
if err.number = 0 then
strMsg = conScriptName & ": Updated registry " & conOutlookDisableAutoArchiveKey
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
else
intLoc = 20
strMsg = conScriptName & ": Error @ " & intLoc & " Num = " & Err.number & " " & Err.Description
DoError(strMsg) ' Failed to execute
end if
else
strMsg = conScriptName & ": Registry not updated, value already set for " & conOutlookDisableAutoArchiveKey
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
end if
' Disable creating any pst files? 1=yes, 0=no (if no registry, treated as = 0)
varTemp = ""
varTemp = obJShell.RegRead(conOutlookDisableCreatePSTfilesKey)
bolRegKeyExists = (err.number = 0)
err.Clear
if Not bolRegKeyExists or (varTemp <> conRegKeyYes) then
objShell.RegWrite conOutlookDisableCreatePSTfilesKey, conRegKeyYes, "REG_DWORD"
if err.number = 0 then
strMsg = conScriptName & ": Updated registry " & conOutlookDisableCreatePSTfilesKey
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
else
intLoc = 23
strMsg = conScriptName & ": Error @ " & intLoc & " Num = " & Err.number & " " & Err.Description
DoError(strMsg) ' Failed to execute
end if
else
strMsg = conScriptName & ": Registry not updated, value already set for " & conOutlookDisableCreatePSTfilesKey
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
end if
' Disable Outlook menu items KB309136
' TCID1 5575 Disable option to create a PST (File>New>Outlook Data File)
' TCID2 5576 Disable option to open a PST (File>Open>Outlook Data File)
strKey = conOutlookDisabledCmdBarKey & "\TCID1" ' Unique value for menu disable
varNewValue = "5575" ' Disable option to create a PST
objShell.RegWrite strKey, varNewValue, "REG_SZ"
if err.number = 0 or err.number = 500 then
err.Clear
strMsg = conScriptName & ": Updated registry " & strKey
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
else
intLoc = 25
strMsg = conScriptName & ": Error @ " & intLoc & " Num = " & Err.number & " " & Err.Description
DoError(strMsg) ' Failed to execute
end if
strKey = conOutlookDisabledCmdBarKey & "\TCID2" ' Unique value for menu disable
varNewValue = "5576" ' Disable option to open a PST
objShell.RegWrite strKey, varNewValue, "REG_SZ"
if err.number = 0 or err.number = 500 then
err.Clear
strMsg = conScriptName & ": Updated registry " & strKey
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
else
intLoc = 30
strMsg = conScriptName & ": Error @ " & intLoc & " Num = " & Err.number & " " & Err.Description
DoError(strMsg) ' Failed to execute
end if
end if ' Registry Entry update
' ============================================================
' The End
' ============================================================
strMsg = "END: " & conScriptName
if conDEBUG then Wscript.Echo strMsg
objShell.LogEvent 0,strMsg
Set objNetwork = Nothing
' ======================================================
Function DoError(strErrMsg)
On Error Resume Next
Dim objShell
if conDEBUG then Wscript.Echo strErrMsg
Set objShell=CreateObject("wscript.shell")
objShell.LogEvent 1,strErrMsg
End Function
No comments:
Post a Comment