Jump to content

Outlook Online/Offline


exodius
 Share

Recommended Posts

I'm trying to port over the following code... It tells you if Outlook is set to Work Offline or not...

$objSession = ObjCreate("MAPI.Session")

$objSession.Logon ("", "", False, False)

$objInfostore = $objSession.GetInfoStore($objSession.Inbox.StoreID)

$bolOffline = $objInfostore.Fields("&H6632000B")

If $bolOffline Then
  MsgBox (0, "", "Online")
Else
  MsgBox (0, "", "Not Online")
EndIf

The original code is:

MsgBox "Online = " & IsOutlookOnline


Function IsOutlookOnline()

   Dim objSession
   Dim objInfoStore
   Dim bolOffline

   Set objSession = CreateObject("MAPI.Session")

   ' Use the existing Outlook session
   objSession.Logon "", "", False, False

   Set objInfostore = objSession.GetInfoStore(objSession.Inbox.StoreID)

   ' Check if it's offline
   bolOffline = objInfostore.Fields(&H6632000B) 'PR_STORE_OFFLINE

   If bolOffline Then
      IsOutlookOnline = False
   Else
      IsOutlookOnline = True
   End If

   Set objInfoStore = Nothing
   Set objSession = Nothing

End Function

What am I doing wrong? Also, does anyone know if there's a way to then change Outlook to being in Work Offline mode and vice versa?

Link to comment
Share on other sites

  • Moderators

This works for me.

Const $PR_STORE_OFFLINE = 0x6632000B

ConsoleWrite(IsOutlookOnline() & @CR)

Func IsOutlookOnline()
    Local $oSession, $oInfoStore, $bOffline

    $oSession = ObjCreate("MAPI.Session")
    
    ; Use the existing Outlook session
    $oSession.Logon ("", "", False, False)
    
    $oInfostore = $oSession.GetInfoStore($oSession.Inbox.StoreID)
    
    ; Check if it's offline
    $bOffline = $oInfostore.Fields($PR_STORE_OFFLINE) ;PR_STORE_OFFLINE
    
    $oInfoStore = 0
    $oSession = 0
    
    If $bOffline Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...