|
How to Run a MAPI Application as a Windows Service with AlwaysUp |
Start sending email from your Extended MAPI program as soon as your PC boots, before any one logs on. Keep it running 24x7!
Microsoft's Messaging Application Programming Interface (MAPI)
allows Windows applications to send and receive email.
To configure a MAPI-enabled application with AlwaysUp:
-
First, you must prepare your MAPI code to operate properly when run in the context of a Windows Service. We suggest the following changes:
-
Initialize MAPI for use in a service by specifying MAPI_NT_SERVICE to MAPIInitialize. For example:
MAPIINIT_0 MAPIINIT = { 0, MAPI_NT_SERVICE };
hRes = MAPIInitialize(&MAPIINIT);
-
Call MAPILogonEx with the MAPI_NT_SERVICE flag, for example:
flFlags = MAPI_NEW_SESSION | MAPI_EXTENDED | MAPI_NT_SERVICE
| MAPI_LOGON_UI;
hRes = MAPILogonEx(
0L, // Handle to parent window or 0.
lpszProfileName, // Default profile name.
lpszPassword, // User password for MAPI session.
flFlags, // Various session settings
&ses // Return handle to MAPI Session
);
Note: If you would like your program to continue to operate normally outside of a Windows Service, we recommend using a command line flag to identify when running as a service and changing the code to react accordingly.
For example, our sample application (configured below) only invokes the above changes when it is passed the /RunService flag on the command line.
-
Download and install AlwaysUp, if necessary.
-
Start AlwaysUp.
-
Select Application > Add to open the Add Application window:
-
On the General tab:
-
In the Application field, enter the full path to your MAPI executable.
We'll specify our sample application in:
C:\MAPI\MAPIServer.exe
-
In the Name field, enter the name that you will call the application in AlwaysUp.
We have used MAPI Server but you can specify almost anything you like.
-
If your executable needs one or more arguments, enter them in the Arguments field.
Our sample application will take /RunService, to tell it to initialize MAPI as in step 1.
-
Click over to the Logon tab and enter the user name and password of the account in which you installed and configured your MAPI application.
-
Click over to the Startup tab and check the Ensure that the Windows Networking components have started box.
This informs AlwaysUp that the MAPI application needs TCP/IP networking support to do its work.
-
Click the Save button. In a couple of seconds, an application called MAPI Server will show up in the AlwaysUp window.
It is not yet running though.
-
To start the server choose Application > Start "MAPI Server".
On Windows 7, 2008 or Vista (or when connecting via RDP), you will have to choose Application > Start "MAPI Server" in this Session if you wish to show your application's windows.
(More on this in the AlwaysUp FAQ.)
-
That's it! Next time your computer boots, your MAPI application will start up immediately, before anyone logs on.
We encourage you to edit the entry in AlwaysUp and check out the many other settings that may be appropriate for your environment.
MAPI Application not working properly as a Windows Service?
-
From AlwaysUp, select Application > Report Activity > Today... to bring up a HTML report detailing the interaction between AlwaysUp and your application.
The AlwaysUp Event Log Messages page explains the more obscure messages.
-
Running a MAPI application unattended can be tricky, especially if it throws up dialog boxes and other windows that
interrupt the action. If these can not be eliminated you may want to investigate using an automation script/program
to automatically dismiss the pesky windows. Please see the
Automate tab
(or the AlwaysUp User's Manual)
for additional information on automation with AlwaysUp.
-
See "How To MAPI Enable a Windows NT Service" for a discussion on other issues when running as a service.
- Consult the AlwaysUp FAQ for answers to commonly asked questions and troubleshooting tips.
- Contact us and we will be happy to help!
|
Over 94,000 installations, and counting!
|
|
|
Rock-solid for the past 19+ years!
|
Fully Compatible with 160+ Applications...
|