Solved

Connection state (Offline mode too)

Posted on 2002-04-23
17
474 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:HStrix
  • 9
  • 4
  • 4
17 Comments
 
LVL 9

Expert Comment

by:rjcpjc
ID: 6963089
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
 

Author Comment

by:HStrix
ID: 6965560
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
 
LVL 9

Expert Comment

by:rjcpjc
ID: 6966012
Try this code instead:  

bolOffline= objInfoStore.Fields.Item(PR_STORE_OFFLINE).Value
0
 

Author Comment

by:HStrix
ID: 6966055
Same error occurred.
?
0
 
LVL 9

Expert Comment

by:rjcpjc
ID: 6966093
Are you sure that CDO is installed?  Its not by default with Outlook 2000.
0
 

Author Comment

by:HStrix
ID: 6966218
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
 
LVL 9

Expert Comment

by:rjcpjc
ID: 6966224
Try to run Outlook setup and make sure that CDO is installed there.  I'll keep looking.
0
 

Author Comment

by:HStrix
ID: 6966904
OK, I'll check it next time.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 16

Expert Comment

by:Neo_mvps
ID: 6971598
Do you have offline storage setup on the profile that you are testing with?
0
 

Author Comment

by:HStrix
ID: 6971947
No, I haven't setup an offline storage file.
0
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 6972114
Set one up with offline storage configured and try Patricia's code sample again.
0
 

Author Comment

by:HStrix
ID: 6973604
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
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 6974896
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
 

Author Comment

by:HStrix
ID: 6976430
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
 
LVL 16

Accepted Solution

by:
Neo_mvps earned 100 total points
ID: 6979080
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
 

Author Comment

by:HStrix
ID: 6981267
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
 

Author Comment

by:HStrix
ID: 7010303
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now