Friday, January 21, 2011

Outlook Anywhere Configuration by Script (GPO/Login Script)

Outlook Anywhere Configuration by Script (GPO/Login Script)


Need to configure your Outlook Clients for Outlook Anywhere? You can do this with a VBScript that you can plug into a GPO or run it as part of your login script. There aren't a whole lot of articles out there about this, one, maybe two of any real use. So I need to make sure I give credit for getting me started on this path to begin with.

Cyrus: http://cyrusbuilt.net/wordpress/?p=150

Anyhow, on to the show! So taking the info from the previously mentioned article, some C# and some VBS and I have a way you can change users mail settings for Outlook Anywhere. As of right now, it will only setup the Server name, on Fast/Slow networks, and Authentication methods.

You need to get hex values, so I wrote this page with C# to generate part of the VBScript code for you. Use this link to generate the Code that goes in between these blocks in the code
http://www.intellus.net/support/HexConverterInline.aspx

The script you want to download is here:
http://www.intellus.net/support/OutlookAnywhereConfig.txt

Basically, here is what the keys do:

Reg Value: 00036623
Represents the "connect using HTTP Fast or Slow" settings
off = key doesn't exist
on only 03 00 00 00
on + slow 23 00 00 00
on + fast 0b 00 00 00
on + fast + slow 2b 00 00 00

Reg Value: 00036627
Represents the Authentication type
01 00 00 00 = Basic
02 00 00 00 = NTLM

The script is currently setup for "mail.testdomain.com"


'**********************************************************************************************
'**********************************************************************************************
'**********************************BEGIN VARIABLE BLOCK****************************************
'**********************************************************************************************
'**********************************************************************************************
'**********************************************************************************************
iKey1="00036623"
iValue1 = Array(&H2b,&H00,&H00,&H00)


iKey2 = "00036627"
iValue2 = Array(&H01,&H00,&H00,&H00)


iKey3 = "001f6622"
iValue3 = Array(&H6D,&H00,&H61,&H00,&H69,&H00,&H6C,&H00,&H2E,&H00,&H74,&H00,&H65,&H00,&H73,&H00,&H74,&H00,&H64,&H00,&H6F,&H00,&H6D,&H00,&H61,&H00,&H69,&H00,&H6E,&H00,&H2E,&H00,&H63,&H00,&H6F,&H00,&H6D,&H00,&H00)
'**********************************************************************************************
'**********************************************************************************************
'***********************************END VARIABLE BLOCK*****************************************
'**********************************************************************************************
'**********************************************************************************************
'**********************************************************************************************




Follow these instructions.
1. First copy the script below to a file and rename it to *.vbs.
http://www.intellus.net/support/OutlookAnywhereConfig.txt
OR
Copy the code below between
"************************Script Begin************************"
and
"************************Script End************************"
2. Next hit this link to determine what settings you want. When you select your settings, it generate the HEX strings required.
3. Once you get the settings, copy and paste it into your script and replace the big block of stars that
say "REPLACE ME WITH THE CODE FROM THE HEX GENERATOR"



*** Here's the fine print: I offer no guarantees on this, please use at your own risk. Make sure you test this on a test environment over and over to make sure it does what you want it to do.
Feel free to contact me if you have any questions though!







"************************Script Begin************************"
'--------------------------------------------------------------------------------
'
'
'
'
'
' Outlook Anywhere Config via Login Script
' Will configure Outlook Client
' 1/1/2011
' Author Name
'
' connect using HTTP
' off = key doesn't exist
' on only 03 00 00 00
' on + slow 23 00 00 00
' on + fast 0b 00 00 00
' on + fast + slow 2b 00 00 00
'
' Auth type
' 01 00 00 00 = Basic
' 02 00 00 00 = NTLM
'
'
'
'
'--------------------------------------------------------------------------------
On Error Resume Next

Const HKEY_CURRENT_USER = &H80000001

strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
strSubKeyPath = "\13dbb0c8aa05101a9bb000aa002fc45a"

blnResult1 = true
blnResult2 = true
blnResult3 = true

'**********************************************************************************************
'**********************************************************************************************
'**********************************BEGIN VARIABLE BLOCK****************************************
'**********************************************************************************************
'**********************************************************************************************
'**********************************************************************************************
iKey1="00036623"
iValue1 = Array(&H2b,&H00,&H00,&H00)


iKey2 = "00036627"
iValue2 = Array(&H01,&H00,&H00,&H00)


iKey3 = "001f6622"
iValue3 = Array(&H6D,&H00,&H61,&H00,&H69,&H00,&H6C,&H00,&H2E,&H00,&H74,&H00,&H65,&H00,&H73,&H00,&H74,&H00,&H64,&H00,&H6F,&H00,&H6D,&H00,&H61,&H00,&H69,&H00,&H6E,&H00,&H2E,&H00,&H63,&H00,&H6F,&H00,&H6D,&H00,&H00)
'**********************************************************************************************
'**********************************************************************************************
'***********************************END VARIABLE BLOCK*****************************************
'**********************************************************************************************
'**********************************************************************************************
'**********************************************************************************************



'get the registry key object for strKeyPath
objReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubkeys

'loop through all keys in the strKeyPath so you get all profile names in there.
For Each strSubkey In arrSubkeys

strKeyPathFull = strKeyPath & "\" & strSubKey

'get the first value to determine if Outlook Anywhere is turned on
strReturn = objReg.GetBinaryValue(HKEY_CURRENT_USER, strKeyPathFull & strSubKeyPath,iKey1, arrVal)

'if exists, then proceed
if strReturn = 0 then

'*****************************************Begin Options Key****************************************************
'Options key - check to see if theres a match, if not, change it, if match, then bypass
'get the current value for server, if there's a match, proceed to correct auth key
strReturn1 = objReg.GetBinaryValue(HKEY_CURRENT_USER, strKeyPathFull & strSubKeyPath,iKey3, arrVal1)
'if exists, then proceed
if strReturn1 = 0 then
for i1 = 0 to ubound(arrVal1)
for i2 = 0 to ubound(iValue1)
if i1=i2 then
if arrVal1(i1) <> iValue1(i2) then
blnResult1 = false
'msgbox "nomatch3: " & arrVal2(i1) & " " & iValue3(i2)
end if
end if
next
next
end if
'No match make the change, else bypass
if blnResult1 = false then
'make the change
objReg.SetBinaryValue HKEY_CURRENT_USER,strKeyPathFull & strSubKeyPath,iKey1,iValue1
end if
'*****************************************End Options Key****************************************************



'*****************************************Begin Auth Type Key****************************************************
'Auth type key - check to see if theres a match, if not, change it, if match, then bypass
'get the current value for server, if there's a match, proceed to correct auth key
strReturn2 = objReg.GetBinaryValue(HKEY_CURRENT_USER, strKeyPathFull & strSubKeyPath,iKey2, arrVal2)
'if exists, then proceed
if strReturn2 = 0 then
for i1 = 0 to ubound(arrVal2)
for i2 = 0 to ubound(iValue2)
if i1=i2 then
if arrVal2(i1) <> iValue2(i2) then
blnResult2 = false
'msgbox "nomatch2: " & arrVal2(i1) & " " & iValue2(i2)
end if
end if
next
next
end if
'No match make the change, else bypass
if blnResult2 = false then
'make the change
objReg.SetBinaryValue HKEY_CURRENT_USER,strKeyPathFull & strSubKeyPath,iKey2,iValue2
end if
'*****************************************End Auth Type Key****************************************************


'*****************************************Begin Server Key****************************************************
'Server key - check to see if theres a match, if not, change it, if match, then bypass
'get the current value for server, if there's a match, proceed to correct auth key
'get the 2nd key, if correct, bypass, if wrong, then correct it
strReturn3 = objReg.GetBinaryValue(HKEY_CURRENT_USER, strKeyPathFull & strSubKeyPath,iKey3, arrVal3)

'build comparison to see if it's the same, if same bypass, if different, correct (set to basic)
if strReturn3 = 0 then
for i1 = 0 to ubound(arrVal3)
for i2 = 0 to ubound(iValue3)
if i1=i2 then
if arrVal3(i1) <> iValue3(i2) then
blnResult3 = false
'msgbox "nomatch3: " & arrVal3(i1) & " " & iValue3(i2)
end if
end if
next
next
end if
'if there's a match, then bypass, if no match, then correct it
if blnResult3 = false then
'msgbox "setting keys" & vbcrlf & strKeyPathFull & strSubKeyPath & vbcrlf & iKey2
objReg.SetBinaryValue HKEY_CURRENT_USER,strKeyPathFull & strSubKeyPath,iKey3,iValue3
end if
'*****************************************End Server Key****************************************************

else
'key doesn't exist - Outlook Anywhere is not turned on for this profile
end if

next

"************************Script End************************"