Microsoft KB Archive/244343

{|
 * width="100%"|

PRB: Microsoft MAPI Control Changes the Current Working Directory

 * }

Q244343

-

The information in this article applies to:


 * Microsoft Visual Basic Learning Edition for Windows, version 6.0
 * Microsoft Visual Basic Professional Edition for Windows, version 6.0
 * Microsoft Visual Basic Enterprise Edition 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) From the File menu, select Make Project1.exe to compile your project.
 * 6) 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.