VBscript to Tell the Last Time the OAB was Downloaded

Friday, June 4, 2010

From the "Random Scripts" dumpster, here's a VBscript I wrote that will show you the date and time that the Offline Address Book (OAB) was downloaded by Outlook for the current user on the local machine.
'OABtime.vbs

'Jeff Guillet, 05/15/2010
'This script reads from the registry To find the last time the user downloaded the OAB.
'Converts REG_BINARY value To a 64-bit FILETIME readable value

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Dim a(7), oRegistry, oMethod, oInParam, oOutParam, objShell

' REG_BINARY Value we're querying from the registry
sMethod = "GetBinaryValue"
hTree = HKEY_CURRENT_USER
' The OABs GUID will be different for each Exchange org, adjust for your org
sKey = "Software\Microsoft\Exchange\Exchange Provider\OABs\20eaa7ed-54a6-404e-ab59-2928e749aabb"
sValue = "OAB Last Modified Time"

Set oRegistry = GetObject("winmgmts:impersonationLevel=impersonate}//./root/default:StdRegProv")
Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()

oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey
oInParam.sValueName = sValue

Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
For iCount = 0 To UBound(oOutParam.Properties_("uValue"))
   a(iCount)=oOutParam.Properties_("uValue")(iCount)
Next

' Obtain local Time Zone bias from machine registry
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngBiasKey)) = "LONG" Then
   lngBias = lngBiasKey
ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
   lngBias = 0
   For k = 0 To UBound(lngBiasKey)
      lngBias = lngBias + (lngBiasKey(k) * 256^k)
   Next
End If

On Error Resume Next
lngHigh = 0
lngLow = 0
For i = 7 To 4 Step -1
   lngHigh = lngHigh * 256 + a(i)
Next
For i=3 To 0 Step -1
   lngLow = lngLow * 256 + a(i)
Next
If err.number <> 0 Then
   dtmDate = #1/1/1601#
   Err.Clear
Else
   If lngLow < 0 Then
      lngHigh = lngHigh + 1
   End If
   If (lngHigh = 0) And (lngLow = 0 ) Then
      dtmDate = #1/1/1601#
   Else
      dtmDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) + lngLow)/600000000 - lngBias) / 1440
   End If
End If

MsgBox "Last OAB Download: " & dtmDate, vbInformation, "Outlook OAB Download"

1 comment:

  1. http://xunyangit.spaces.live.com/blog/cns!F934535AFC3723BA!3335.entry

    i followed an ps script

    ReplyDelete

Thank you for your comment! It is my hope that you find the information here useful. Let others know if this post helped you out, or if you have a comment or further information.