See below:
'Find version of OUtlook being used.
'Option Explicit
Function GetOutlookBitVersion()
Dim oRegistry
Dim oFSO
Dim sKey
Dim sAppExe
Dim sValue
Dim sAppVersion
Dim sOutlookVersion
Dim sOutlookRegKey
Dim WSHShell
Dim sRegvalue
Const HKEY_LOCAL_MACHINE = &H80000002
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/default:StdRegProv")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sKey = "Software\Microsoft\Windows\CurrentVersion\App Paths"
sAppExe = "outlook.exe"
oRegistry.GetStringValue HKEY_LOCAL_MACHINE, sKey & "\" & sAppExe, "", sValue
if not IsNull(sValue) then
sOutlookVersion = Left(oFSO.GetFileVersion(sValue), 2)
sOutlookRegKey = "HKEY_LOCAL_MACHINE\software\Microsoft\Office\" & sOutlookVersion & ".0\Outlook\Bitness"
Set WSHShell = CreateObject("WScript.Shell")
sRegvalue = WSHShell.RegRead(sOutlookRegKey)
if err.number <> 0 then
GetOutlookBitVersion = "error"
else
GetOutlookBitVersion = sRegvalue
end if
else
GetOutlookBitVersion = "error"
end if
Set oFSO = Nothing
Set oRegistry = Nothing
End Function
'wscript.echo GetOutlookBitVersion()
Function GetMailServerName()
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
' Constants for formats used for representing distinguished names.
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1 'RFC 1779
' Determine DNS name of domain from RootDSE.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
'Get the username from environment variable
Set wshNet = CreateObject( "WScript.network" )
strUserName = wshNet.username
Set wshNet = Nothing
If (strUserName = "") Then
wscript.Quit
End If
' Use the Set method to specify the NT format of the user name.
' Trap error if user does not exist.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strUserName
If (Err.Number <> 0) Then
On Error GoTo 0
'Wscript.Echo "User " & strUserName & " does not exist"
Wscript.Quit
End If
On Error GoTo 0
' Use the Get method to retrieve the RPC 1779 Distinguished Name.
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Bind to the user object.
Set objUser = GetObject("LDAP://" & strUserDN)
' Obtain mail-homeserver attribute of AD user.
On Error Resume Next
strMailActive = objUser.[kerio-Mail-Active]
If (strMailActive = "") Then
strMailServerCode = "NoMailbox"
Else
strMailServerCode = objUser.[kerio-Mail-HomeServer]
If (Err.Number <> 0) Then
On Error GoTo 0
'Wscript.Echo Err.Description
Wscript.Quit
End If
End If
select case strMailServerCode
case "NoMailbox"
GetMailServerName = "None"
case "c0a22478-78f7-440c-bc4b-658826ea671a"
GetMailServerName = "mail1.wpi.com"
case "5a296c5e-f321-4ff3-982e-01d3068296b5"
GetMailServerName = "mail.wpi.com"
case else
GetMailServerName = mail.wpi.com
End Select
End Function 'GetMailServerName
'wscript.echo GetMailServerName()
Dim sMailServer
Dim sOutlookBitVersion
sMailServer = GetMailServerName()
sOutlookBitVersion = GetOutlookBitVersion()
Select case sOutlookBitVersion
case "error"
wscript.quit
case "x86"
sRunApp = "C:\Program Files (x86)\Kerio\Outlook Connector (Offline Edition)\PROFILECREATOR.exe"
case else
sRunApp = "C:\Program Files\Kerio\Outlook Connector (Offline Edition)\PROFILECREATOR.exe"
End Select
Select case sMailServer
case "mail.wpi.com"
if (sOutlookBitVersion = "x86") then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Program Files (x86)\Kerio\Outlook Connector (Offline Edition)\PROFILECREATOR.exe"" /profile=WPI /host=mail.wpi.com /spa /rename", 1, True
Set objShell = Nothing
else
if (sOutlookBitVersion = "x64") then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Program Files\Kerio\Outlook Connector (Offline Edition)\PROFILECREATOR.exe"" /profile=WPI /host=mail.wpi.com /spa /rename", 1, True
Set objShell = Nothing
end if
end if
case "mail1.wpi.com"
if (sOutlookBitVersion = "x86") then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Program Files (x86)\Kerio\Outlook Connector (Offline Edition)\PROFILECREATOR.exe"" /profile=WPI /host=mail1.wpi.com /spa /rename", 1, True
Set objShell = Nothing
else
if (sOutlookBitVersion = "x64") then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Program Files\Kerio\Outlook Connector (Offline Edition)\PROFILECREATOR.exe"" /profile=WPI /host=mail1.wpi.com /spa /rename", 1, True
Set objShell = Nothing
end if
end if
case else
wscript.quit
End Select