Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting Cached Exchange Mode

Status
Not open for further replies.

marble2wist

IS-IT--Management
Dec 10, 2006
5
US
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
 
If all you have is the script you posted, then it looks like there are pieces missing. Seems there are calls to functions or subs that are not included in this example. Seems that you can switch the cached mode by making registry changes. I found this site which shows you what values you can use.


I tried the value of 04 00 00 00 to disable and it worked, then I used 04 05 00 00 to enable the cached mode to the way it was on my machine originally.

dm4ever
--------------------------------------------------------------------------------
My approach to things: K.I.S.S - Keep It Simple Stupid
 
I looked at that option but am not sure how to write a VBSCript Script to Incorporate that.
 
You could also use WMI and the stdregprov to set your desired values. I found a thread in another forum where a member showed various examples of using this method. One of the methods he shows an example of is setting a binary value which is what you would need in this case.

dm4ever
--------------------------------------------------------------------------------
My approach to things: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top