[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Script that changes the cached mode status. need help with this script.

Posted on 2010-03-27
7
Medium Priority
?
1,618 Views
Last Modified: 2012-06-21
Hi,

The below script changes the status of cached mode of Outlook. when changed from false to true and true to false.

Can i have help with some changes. To have a message stating staus now is enabled. Going to disable. To enable it back please run again.
And the script that to be changed in such a way that if enabled it has to get disabled and if disabled it has to be enabled.

Any help is greatly appretiated.

Regards
Sharath
' Script to enable - or - disable Outlook Cache Mode. 
'

Option Explicit

'On error resume next

' Environment specific Consts

' Path to your log file
Const LogFile = "\\im\logs\Cached.log"

' Whether to enable Cache Mode on clients where this is currently disabled
Const EnableCacheMode = true

' Whether to disable Cache Mode on clients where this is currently enabled
Const DisableCacheMode = false

' Setting both EnableCacheMode and DisableCacheMode to false will report the status of ol cached mode on the client only

' End Environment specific Consts


' Registry Constants
Const HKCU = &H80000001
Const RegKeyProfiles = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
Const RegKeyName = "13dbb0c8aa05101a9bb000aa002fc45a"
Const RegValueName = "00036601"

' Global Variables
dim arrDisabledValue : arrDisabledValue = Array(&H04,&H00,&H00,&H00) ' value to set disabled
dim arrEnabledValue : arrEnabledValue = Array(&H84,&H01,&H00,&H00) ' value to set enabled (w/o PF's)
dim arrEnabledValueWithPF : arrEnabledValueWithPF = Array(&H84,&H05,&H00,&H00) ' value to set enabled with Public Folder Favourites

Dim ArrAllSubKeys, arrValueTypes, arrValues, objSubKey, subval, sValue, iret
Dim fullKeyPath
Dim oRegWMIProv
Dim oFso
Dim oLogFile
Dim oNet
Dim sComputerName
Dim sUserName

if EnableCacheMode and DisableCacheMode then
    Wscript.echo "Invalid configuration!  You cannot have both EnableCacheMode and DisableCacheMode enabled at the same time.  Quitting.."
    Wscript.quit(-1)
end if

Set oNet = CreateObject("Wscript.Network")
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oRegWMIProv = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

sUserName = oNet.UserName
sComputerName = oNet.ComputerName

if oFso.FileExists(LogFile) then
    Set oLogFile = oFso.OpenTextFile(LogFile, 8)
    else
    Set oLogFile = oFso.CreateTextFile(LogFile, False)
    oLogFile.Writeline "ComputerName,UserName,ProfileName,OLCachedModeStatus"
end if

' List all subkeys (Profiles)
oRegWMIProv.EnumKey HKCU, RegKeyProfiles, ArrAllSubKeys
For Each objSubKey In arrAllSubKeys ' looping profiles
 Wscript.echo "Profile " & objSubKey
 fullKeyPath = RegKeyProfiles & "\" & objSubKey & "\" & RegKeyName

 ' enum all values under the cached mode reg id key
 oRegWMIProv.EnumValues HKCU, fullKeyPath, arrValues, arrValueTypes

 for each subval in arrValues
  ' if the sub value is the one we are interested in then process it
  If subval = RegValueName Then
    oRegWMIProv.GetBinaryValue HKCU, fullKeyPath, subval, sValue
    If (sValue(0) = arrDisabledValue(0)) AND (sValue(1) = arrDisabledValue(1)) AND (sValue(2) = arrDisabledValue(2)) AND (sValue(3) = arrDisabledValue(3)) Then

      oLogFile.WriteLine sComputerName& "," &  sUserName& "," &  objSubKey& "," &  "Cached Mode Disabled"
      Wscript.echo sComputerName& "," &  sUserName& "," &  objSubKey& "," &  "Cached Mode Disabled"

      if  EnableCacheMode then
        Wscript.echo objSubKey & " Disabled (enabling)"
        iret = oRegWMIProv.SetBinaryValue (HKCU,fullKeyPath,RegValueName,arrEnabledValue)
        oLogFile.WriteLine sComputerName& "," &  sUserName& "," &  objSubKey& "," &  "Cached Mode Now Enabled"
      end if

    else

      oLogFile.WriteLine sComputerName & "," & sUserName& "," & objSubKey & "," &  "Cached Mode Enabled"
      Wscript.echo sComputerName& "," &  sUserName& "," &  objSubKey& "," &  "Cached Mode Enabled"

      if DisableCacheMode then 
         Wscript.echo objSubKey & "Enabled (disabling)"
         oLogFile.WriteLine sComputerName& "," &  sUserName& "," &  objSubKey& "," &  "Cached Mode Now Disabled"
         iret = oRegWMIProv.SetBinaryValue (HKCU,fullKeyPath,RegValueName,arrDisabledValue)
      End If

  End If

  End If

 Next

Next

oLogFile.Close()

Set oRegWMIProv = Nothing
Set oFso = Nothing
Set oLogFile = Nothing
Set objSubKey = Nothing
Set oRegWMIProv = Nothing

Open in new window

0
Comment
Question by:bsharath
  • 4
  • 2
7 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 1400 total points
ID: 28944151
Hi, try this.  I think it should work as is, without any changes.  When you run it, it toggle the cached mode state, to the opposite of what it currently is.

Regards,

Rob.
' Script to enable - or - disable Outlook Cache Mode.  
' 
 
Option Explicit 
 
'On error resume next 
 
' Environment specific Consts 
 
' Path to your log file 
Const LogFile = "\\im\logs\Cached.log" 
 
' Whether to enable Cache Mode on clients where this is currently disabled 
'Const EnableCacheMode = True 
 
' Whether to disable Cache Mode on clients where this is currently enabled 
'Const DisableCacheMode = False 
 
' Setting both EnableCacheMode and DisableCacheMode to false will report the status of ol cached mode on the client only 
 
' End Environment specific Consts 
 
 
' Registry Constants 
Const HKCU = &H80000001 
Const RegKeyProfiles = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" 
Const RegKeyName = "13dbb0c8aa05101a9bb000aa002fc45a" 
Const RegValueName = "00036601" 
 
' Global Variables 
Dim arrDisabledValue : arrDisabledValue = Array(&H04,&H00,&H00,&H00) ' value to set disabled 
Dim arrEnabledValue : arrEnabledValue = Array(&H84,&H01,&H00,&H00) ' value to set enabled (w/o PF's) 
Dim arrEnabledValueWithPF : arrEnabledValueWithPF = Array(&H84,&H05,&H00,&H00) ' value to set enabled with Public Folder Favourites 
 
Dim ArrAllSubKeys, arrValueTypes, arrValues, objSubKey, subval, sValue, iret 
Dim fullKeyPath 
Dim oRegWMIProv 
Dim oFso 
Dim oLogFile 
Dim oNet 
Dim sComputerName 
Dim sUserName 
 
'If EnableCacheMode And DisableCacheMode Then 
'	Wscript.echo "Invalid configuration!  You cannot have both EnableCacheMode and DisableCacheMode enabled at the same time.  Quitting.." 
'	Wscript.quit(-1) 
'End If 
 
Set oNet = CreateObject("Wscript.Network") 
Set oFso = CreateObject("Scripting.FileSystemObject") 
Set oRegWMIProv = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") 
 
sUserName = oNet.UserName 
sComputerName = oNet.ComputerName 
 
If oFso.FileExists(LogFile) Then 
	Set oLogFile = oFso.OpenTextFile(LogFile, 8) 
Else 
	Set oLogFile = oFso.CreateTextFile(LogFile, False) 
	oLogFile.Writeline "ComputerName,UserName,ProfileName,OLCachedModeStatus" 
End If 
 
' List all subkeys (Profiles) 
oRegWMIProv.EnumKey HKCU, RegKeyProfiles, ArrAllSubKeys 
For Each objSubKey In arrAllSubKeys ' looping profiles 
	Wscript.echo "Profile " & objSubKey 
	fullKeyPath = RegKeyProfiles & "\" & objSubKey & "\" & RegKeyName 
 
	' enum all values under the cached mode reg id key 
	oRegWMIProv.EnumValues HKCU, fullKeyPath, arrValues, arrValueTypes 
 
	For Each subval In arrValues 
		' if the sub value is the one we are interested in then process it 
		If subval = RegValueName Then 
			oRegWMIProv.GetBinaryValue HKCU, fullKeyPath, subval, sValue 
			If (sValue(0) = arrDisabledValue(0)) And (sValue(1) = arrDisabledValue(1)) And (sValue(2) = arrDisabledValue(2)) And (sValue(3) = arrDisabledValue(3)) Then 
 
				oLogFile.WriteLine sComputerName& "," &  sUserName& "," &  objSubKey& "," &  "Cached Mode Disabled" 
      			Wscript.echo sComputerName& "," &  sUserName& "," &  objSubKey& "," &  "Cached Mode Disabled" 
 
      			'If  EnableCacheMode Then 
        			Wscript.echo objSubKey & " Disabled (enabling)" 
        			iret = oRegWMIProv.SetBinaryValue (HKCU,fullKeyPath,RegValueName,arrEnabledValue) 
        			oLogFile.WriteLine sComputerName& "," &  sUserName& "," &  objSubKey& "," &  "Cached Mode Now Enabled" 
      			'End If
      			
      			WScript.Echo "Cached mode has been enabled. To disable it, run this script again."
 
    		Else 
 
				oLogFile.WriteLine sComputerName & "," & sUserName& "," & objSubKey & "," &  "Cached Mode Enabled" 
				Wscript.echo sComputerName& "," &  sUserName& "," &  objSubKey& "," &  "Cached Mode Enabled" 

				'If DisableCacheMode Then  
					Wscript.echo objSubKey & "Enabled (disabling)" 
					oLogFile.WriteLine sComputerName& "," &  sUserName& "," &  objSubKey& "," &  "Cached Mode Now Disabled" 
					iret = oRegWMIProv.SetBinaryValue (HKCU,fullKeyPath,RegValueName,arrDisabledValue) 
				'End If 
 
      			WScript.Echo "Cached mode has been disabled. To enable it, run this script again."

			End If  
		End If 
	Next 
Next 
 
oLogFile.Close() 
 
Set oRegWMIProv = Nothing 
Set oFso = Nothing 
Set oLogFile = Nothing 
Set objSubKey = Nothing 
Set oRegWMIProv = Nothing

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 28945059
Rob can i get the same script to ask. if i want to enabled or disable.
At present we need to change the false to true and vise versa
0
 
LVL 15

Expert Comment

by:markdmac
ID: 28946028
This one is tough to rewrite because of the need to enumerate the profiles, determine the current state and then toggle it based on the Reg_Binary value.  Can you explain the need for this?  Why don't you use group policy and force the setting you want.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 11

Author Comment

by:bsharath
ID: 28946293
We are iin the Exchange rollout.
When the user runs the profile manager he first needs to disable cache and then once done enable it back

0
 
LVL 11

Author Comment

by:bsharath
ID: 28947160
If i can get 2 script 1 for enablingg and another for disabling i am ok
0
 
LVL 15

Assisted Solution

by:markdmac
markdmac earned 600 total points
ID: 28984712
Have you looked into PRF files?  They allow you to preconfigure the Exchange profiles the way you want them to be.  I know of no way to determine what profile you might want to affect the change on.

For example on my machine I have several profiles to access resource accounts mailboxes directly when I setup shared calendar items for my on call system.
0
 
LVL 11

Author Comment

by:bsharath
ID: 29011486
Thank you. Due to emergency
i changed the false to true and visse versa and saved into 2 vbs files and renamed as enable and disable. Now problem resolved...:-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question