Connection state (Offline mode too)

Hi experts, I'm using a VBA macro (Outlook 2000)
and want to find out wether I'm currently connected to
my Exchange Server or not
(including detection if I'm working in Offline mode
without having network problems)
and
if I'm able to establish a connection to
my Exchange Server (network problems, ??).

How can I do that?
A snippet would be very appreciated.

I expect that the same function can be performed
by a Visual Basix program as well.

HStrix
HStrixAsked:
Who is Participating?
 
Neo_mvpsConnect With a Mentor Commented:
The sample provided is what you would use to determine if you are online/offline from exchange.  The only problem with the code is that it requires you to have offline configured and working from the profile.

Outside of that, Outlook doesn't supply any properties or methods that one can use to determine what state it is in.  However if you do notice that "Unknown" is being returned in the currentuser property, then you might have a workaround.  (e.g. If unknown is being returned, then you don't have a connection to exchange because mapi couldn't initialize the store.)
0
 
rjcpjcCommented:
This is a VBScript macro, but can be adapted for VBA or VB.

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
0
 
HStrixAuthor Commented:
Thank you rjcpjc,
I've incorporated your suggestion as follows:
---
Private Function IsOutlookOnline() As Boolean
Dim objSession   As MAPI.Session ' object
Dim objInfoStore As Object
Dim bolOffline   As Boolean

    Set objSession = CreateObject("MAPI.Session")  ' late binding CDO 2.1

    '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
---
But after execution of  
"bolOffline = objInfoStore.Fields &H6632000B) 'PR_STORE_OFFLINE"
(called at the beginning of "UserForm_Initialize")
I get the following error:
"Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)"
As you can see the referral to CDO 2.1 exists.
What else is missing?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
rjcpjcCommented:
Try this code instead:  

bolOffline= objInfoStore.Fields.Item(PR_STORE_OFFLINE).Value
0
 
HStrixAuthor Commented:
Same error occurred.
?
0
 
rjcpjcCommented:
Are you sure that CDO is installed?  Its not by default with Outlook 2000.
0
 
HStrixAuthor Commented:
My references contain the following entry:
  Microsoft CDO 1.2 Library
  and the path refers to my system's path
  "E:\Program Files\Common Files\System\Mapi\1031\NT\cdo.dll"
  it is dated 1998-06-04 (seems to be service pack 1)
My Outlook's version is 9.0.0.2814
---
Before I referred to CDO I couldn't use
  Dim objSession   As MAPI.Session ' object ' early binding
I had to use
  Dim objSession   As Object                ' lated binding


0
 
rjcpjcCommented:
Try to run Outlook setup and make sure that CDO is installed there.  I'll keep looking.
0
 
HStrixAuthor Commented:
OK, I'll check it next time.
0
 
Neo_mvpsCommented:
Do you have offline storage setup on the profile that you are testing with?
0
 
HStrixAuthor Commented:
No, I haven't setup an offline storage file.
0
 
Neo_mvpsCommented:
Set one up with offline storage configured and try Patricia's code sample again.
0
 
HStrixAuthor Commented:
OK, I'll do this check as well.
But is this really necessary to create an ost file?
If I don't have access to my Exchange server,
I automatically work offline too.
Outlook discovers that and shows only my pst file(s).
And I expect that it is possible to find out such a status in generally.
But how?
0
 
Neo_mvpsCommented:
Yes if you want to determine if Outlook 98/2000 (Corp/Workgroup) and Outlook 97/2002 is offline from an Exchange server.

If you are trying to ascertain if a stand-alone user is offline (which they really can't be since they are using a PST), then you would use the Win32API to determine if they have a valid network connection.
0
 
HStrixAuthor Commented:
Thank you,
but it is still not fully clear to me.
- Outlook is able to detect if the connection to the Exchange Server exists.
  In such a case Outlook is offering the pst file(s) only.
  My target is, to take over that information from Outlook,
  I'm trying to let Outlook do as much work as possible and collect the current existing information.
  Otherwise I'ld have to read the registry, get the name of the Exchange server and do lots of Win32API calls.
  But why should I do the work again what Outlook has done already?
- Secondly there might exist some suspicious status.
  In such a status Outlook detects this, shows only the pst file(s) and offers a user called "Unknown".
  That also means Outlook does have that information.
  The question is where is it and how can I retrieve it?
0
 
HStrixAuthor Commented:
OK, I've implemented a Ping routine.
That helps me getting the proper connection status to the Exchange server.
I think, in a "normal" environment (except for a notebook, ...) nobody will setup an ost file.
The required information for the Ping I'm reading from the registry (HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\).
The result of the Ping I'm using during the further process.
The solution is not as I've expected, but it seems working.

Because of your answers I'ld like to make my question PAQ and share the points between you.
Thank you very much for your help.
But I don't know how to do a sharing.
Perhaps a moderator can help?
0
 
HStrixAuthor Commented:
I could solve my problem based on the hints of rjcpjc and Neo_mvps. In addition I used the information offered on "http://www.dimastr.com/redemption/".
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.