marble2wist
IS-IT--Management
Is there anyone that can help me, am trying to Enable Cached Exchange Mode on multiple computers using VBScript. I found a link ( that gave sounded promising but when I ran the scripts, no errors were created nor did it enable or disable CEM. The script is ran using the following syntax:
cscript CachedExchange.vbs [/P:]
[/enable | /disable] [/V]
Here is the script: Please Let Me Know If Am Missing Anything
Listing 1: The Main Subroutine
Sub Main
Dim lngCLFlags, lngMode, lngRC, strProfile, strVersion, blnVerbose, arrConfig
' BEGIN COMMENT
' Neither /ENABLE or /DISABLE is specified yet.
' END COMMENT
lngCLFlags = CL_NONE
With WScript.Arguments
If .Named.Exists("?") Then Usage
If .Named.Exists("DISABLE") Then lngCLFlags = lngCLFlags Or CL_DISABLE
If .Named.Exists("ENABLE") Then lngCLFlags = lngCLFlags Or CL_ENABLE
strProfile = .Named("P")
blnVerbose = .Named.Exists("V")
End With
If ScriptHost() <> "cscript.exe" Then _
Die "You must run this script using the CScript host.", 1
' BEGIN COMMENT
' Can't specify both /ENABLE and /DISABLE.
' END COMMENT
If ((lngCLFlags And CL_DISABLE) <> 0) _
And ((lngCLFlags And CL_ENABLE) <> 0) Then Usage
' BEGIN COMMENT
' Retrieve the WMI StdRegProv class.
' END COMMENT
Set g_objReg = GetObject("WinMgmts:" _
& "{impersonationlevel=impersonate}!root/default:StdRegProv")
strVersion = GetOutlookVersion()
If blnVerbose Then _
WScript.Echo "Outlook.exe is version " & strVersion
' BEGIN COMMENT
' Outlook must be version 11 (2003) or later.
' END COMMENT
If GetVersionPortion(strVersion, 0) < 11 Then _
Die "Outlook is not installed, or is not version 2003 or later.", 1
If strProfile = "" Then strProfile = GetDefaultProfile()
If strProfile = "" Then _
Die "Unable to determine default Outlook profile.", 2
If blnVerbose Then _
WScript.Echo "Outlook profile: " & strProfile
If Not ProfileKeyExists(strProfile) Then _
Die "Outlook profile registry subkey not found.", 2
' BEGIN COMMENT
' Retrieve the array of bytes from the registry.
' END COMMENT
arrConfig = GetExchangeConfig(strProfile)
' BEGIN COMMENT
' Check the status of the bit that determines cached Exchange mode.
' END COMMENT
lngMode = GetCachedExhangeMode(arrConfig)
If lngMode = -2 Then _
Die "Unable to read cached Exchange mode setting from registry.", 13
If blnVerbose Then _
WScript.Echo "Registry data: " & ByteArrayToString(arrConfig)
If lngCLFlags = CL_NONE Then
WScript.Echo "Cached Exchange mode is currently " _
& IIf(CBool(lngMode), "ENABLED", "DISABLED")
lngRC = IIf(CBool(lngMode), 1, 0)
Else
' BEGIN COMMENT
' Modify the bits in the array to enable cached Exchange mode.
' END COMMENT
SetCachedExchangeMode (lngCLFlags And CL_ENABLE) <> 0, arrConfig
' Write the array of bytes back to the registry.
lngRC = UpdateRegistry(strProfile, arrConfig)
If lngRC = 0 Then
If blnVerbose Then
arrConfig = GetExchangeConfig(strProfile)
WScript.Echo "New registry data: " & ByteArrayToString(arrConfig)
End If
WScript.Echo "Cached Exchange mode is now " _
& IIf((lngCLFlags And CL_ENABLE) <> 0, "ENABLED", "DISABLED")
Else
WScript.Echo "Error updating registry."
End If
End If
WScript.Quit lngRC
End Sub
cscript CachedExchange.vbs [/P:]
[/enable | /disable] [/V]
Here is the script: Please Let Me Know If Am Missing Anything
Listing 1: The Main Subroutine
Sub Main
Dim lngCLFlags, lngMode, lngRC, strProfile, strVersion, blnVerbose, arrConfig
' BEGIN COMMENT
' Neither /ENABLE or /DISABLE is specified yet.
' END COMMENT
lngCLFlags = CL_NONE
With WScript.Arguments
If .Named.Exists("?") Then Usage
If .Named.Exists("DISABLE") Then lngCLFlags = lngCLFlags Or CL_DISABLE
If .Named.Exists("ENABLE") Then lngCLFlags = lngCLFlags Or CL_ENABLE
strProfile = .Named("P")
blnVerbose = .Named.Exists("V")
End With
If ScriptHost() <> "cscript.exe" Then _
Die "You must run this script using the CScript host.", 1
' BEGIN COMMENT
' Can't specify both /ENABLE and /DISABLE.
' END COMMENT
If ((lngCLFlags And CL_DISABLE) <> 0) _
And ((lngCLFlags And CL_ENABLE) <> 0) Then Usage
' BEGIN COMMENT
' Retrieve the WMI StdRegProv class.
' END COMMENT
Set g_objReg = GetObject("WinMgmts:" _
& "{impersonationlevel=impersonate}!root/default:StdRegProv")
strVersion = GetOutlookVersion()
If blnVerbose Then _
WScript.Echo "Outlook.exe is version " & strVersion
' BEGIN COMMENT
' Outlook must be version 11 (2003) or later.
' END COMMENT
If GetVersionPortion(strVersion, 0) < 11 Then _
Die "Outlook is not installed, or is not version 2003 or later.", 1
If strProfile = "" Then strProfile = GetDefaultProfile()
If strProfile = "" Then _
Die "Unable to determine default Outlook profile.", 2
If blnVerbose Then _
WScript.Echo "Outlook profile: " & strProfile
If Not ProfileKeyExists(strProfile) Then _
Die "Outlook profile registry subkey not found.", 2
' BEGIN COMMENT
' Retrieve the array of bytes from the registry.
' END COMMENT
arrConfig = GetExchangeConfig(strProfile)
' BEGIN COMMENT
' Check the status of the bit that determines cached Exchange mode.
' END COMMENT
lngMode = GetCachedExhangeMode(arrConfig)
If lngMode = -2 Then _
Die "Unable to read cached Exchange mode setting from registry.", 13
If blnVerbose Then _
WScript.Echo "Registry data: " & ByteArrayToString(arrConfig)
If lngCLFlags = CL_NONE Then
WScript.Echo "Cached Exchange mode is currently " _
& IIf(CBool(lngMode), "ENABLED", "DISABLED")
lngRC = IIf(CBool(lngMode), 1, 0)
Else
' BEGIN COMMENT
' Modify the bits in the array to enable cached Exchange mode.
' END COMMENT
SetCachedExchangeMode (lngCLFlags And CL_ENABLE) <> 0, arrConfig
' Write the array of bytes back to the registry.
lngRC = UpdateRegistry(strProfile, arrConfig)
If lngRC = 0 Then
If blnVerbose Then
arrConfig = GetExchangeConfig(strProfile)
WScript.Echo "New registry data: " & ByteArrayToString(arrConfig)
End If
WScript.Echo "Cached Exchange mode is now " _
& IIf((lngCLFlags And CL_ENABLE) <> 0, "ENABLED", "DISABLED")
Else
WScript.Echo "Error updating registry."
End If
End If
WScript.Quit lngRC
End Sub