20 May, 2012

change outlook cache mode in batch script

Hi,

Just a small thing I wrote to change the user outlook mode to cached.
======================================================

rem *** get the profile name ***
FOR /F "tokens=1,2,3 delims= " %%A IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" /v DefaultProfile') DO set profile=%%C

rem *** query if Outlook is in cache mode ***
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%profile%\13dbb0c8aa05101a9bb000aa002fc45a" /v 00036601 |find "84010000"
if errorlevel 0 goto end

rem *** change outlook to cache mode ***
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%profile%\13dbb0c8aa05101a9bb000aa002fc45a" /v 00036601 /t REG_BINARY /d 84010000 /f

:end

======================================================



for XP machines the first step did work fine so I wrote a small VB to replace it:

The VB (save it as read.vbs):
======================================================

Option Explicit
Dim Temp

Temp = ReadReg("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\DefaultProfile")
WScript.Echo Temp

Function ReadReg(RegPath)
     Dim objRegistry, Key
     Set objRegistry = CreateObject("Wscript.shell")
     Key = objRegistry.RegRead(RegPath)
     ReadReg = Key
End Function
=======================================================
The corrected CMD:
=======================================================

set profile=
rem *** get the profile name ***
FOR /F "Delims=" %%A IN ('cscript /nologo read.vbs') DO set profile=%%A
echo "Profile: " %profile%

rem *** query if Outlook is in cache mode ***
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%profile%\13dbb0c8aa05101a9bb000aa002fc45a" /v 00036601 |find "84010000"
if %errorlevel%==0 goto end

rem *** change outlook to cache mode ***
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%profile%\13dbb0c8aa05101a9bb000aa002fc45a" /v 00036601 /t REG_BINARY /d 84010000 /f

:end

=======================================================




Enjoy