PRB: Microsoft MAPI Control Changes the Current Working Directory

ID: Q244343


The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0
  • Microsoft Internet Explorer version 5 for Windows NT 4.0


SYMPTOMS

When running a Microsoft Visual Basic application that uses the Microsoft MAPI Control, and that application relies upon the current working directory, the application might not work as expected.


CAUSE

This is due to the fact that the working directory gets changed after calling the SignOn method of the MAPISession object. This was not the behavior prior to installing Internet Explorer 5.0.


RESOLUTION

Instead of relying on the current working directory, which can be modified at run-time, use App.Path or specify the full path of the file.


MORE INFORMATION

There are some procedure or function calls that expect a string containing the path name to a file as one of their parameters. In some cases, you can give it just the filename instead of the whole path to the file. In this case the method or procedure looks for the file in the current working directory. The current working directory is initially set to the directory where the executable file resides. However, the current working directory gets changed by the SignOn method call of the MAPISession object. The current working directory can also be changed in code with the CurDir function. If the file resides in the application's directory, then you can concatenate App.Path to the name of the file. App.Path is read-only at run-time. You can also give the full path name of the file when passing it to the procedure or function. Note that although App.Path is read-only at run-time, this property can get changed by VB when running in the VB IDE. For more information on debug versus compiled mode, refer to the "eferences section below."

Steps to Reproduce Behavior

The following steps assume you already have an Outlook profile set up on your computer. If you do not, please see the "References" section below to link to an article that describes how to set up an Outlook profile.
  1. Create a Standard EXE project in Visual Basic. Form1 is created by default.


  2. From the Project menu, select Components, in the Components dialog box, check Microsoft MAPI Controls 6.0, and click OK.


  3. Add a MAPI Session object and a CommandButton to Form1.


  4. Paste the following code in the General Declarations section of Form1:


  5. 
    Private Sub Command1_Click()
       MsgBox CurDir = App.Path
       MAPISession1.SignOn
       MsgBox CurDir = App.Path
       MAPISession1.SignOff
    End Sub 
  6. From the File menu, select Make Project1.exe to compile your project.


  7. Run the compiled executable and click on Command1.


The first message box displays True, because App.Path is equal to the current working directory. The second message box returns False, because the current working directory is changed by the SignOn method of the MAPISession object.


REFERENCES

For additional information on behavior differences between running projects in the IDE and compiled EXEs, click the article number below to view the article in the Microsoft Knowledge Base:

Q201741 INFO: Differences of Behavior in Debug Mode and Compile Mode
For additional information on creating Outlook user profiles, click the article number below to view the article in the Microsoft Knowledge Base:
Q195718 OL2000: (CW) How to Create a New User Profile for Outlook

Additional query words: Error 53 found Open Statement

Keywords : kbActiveX kbMAPI kbString kbVBp600 kbGrpVB kbIE500 kbDSupport
Version : WINDOWS:5,6.0
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: December 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.