设为首页 收藏本站
查看: 984|回复: 0

[经验分享] 在未安装 Outlook 的情况下创建 MAPI 配置文件

[复制链接]

尚未签到

发表于 2015-9-13 08:58:47 | 显示全部楼层 |阅读模式
  人们通常认为,Exchange Server 上必须安装 MAPI 客户端(例如 Microsoft Outlook 或 Exchange 客户端)才能创建 MAPI 配置文件;这种想法是错误的。因为此原因而安装 MAPI 客户端是不必要的,而且就 Outlook 而言,不建议您在生产服务器上安装它。只要安装有 MAPI 子系统(Exchange 中已经包含此子系统),就可以通过其他各种方法来创建 MAPI 配置文件。

您尝试其中任一种方法之前,您需要确保服务器上的 Mapisvc.inf 文件中生成了适当的项目。 有关如何修改该文件的其他信息,请单击下面的文章编号,以查看 Microsoft 知识库中相应的文章:

294470  (http://support.microsoft.com/kb/294470/EN-US/ ) HOWTO:Add Entries For Exchange Services to Mapisvc.inf
1. 使用 NewProf.exe

此实用工具随 Microsoft Outlook 一起提供。您可以在 MSDN Library 中的“Creating a Profile with NEWPROF”(使用 NEWPROF 创建配置文件)主题下找到它的使用说明。 有关其他信息,请单击下面的文章编号,以查看 Microsoft 知识库中相应的文章:

145905  (http://support.microsoft.com/kb/145905/EN-US/ ) XCLN:Newprof.exe Command-Line Options

148664  (http://support.microsoft.com/kb/148664/EN-US/ ) XCLN:Description of the Profile Descriptor File
2. 使用 ProfMan2 示例

该示例使用 MAPI IProfAdmin 接口(参见下面的方法 5 中的说明)。您可以在以下文章中找到此示例:

228736  (http://support.microsoft.com/kb/228736/EN-US/ ) 示例:Profman2.exe - MAPI 配置文件管理器 v2.0
3. 使用 MAPILogonEx

当调用 MAPILogonEx 而没有指定配置文件并且设置了 MAPI_LOGON_UI 标志时,如果计算机上没有任何配置文件,MAPI 会显示配置文件创建向导。如果有现有的配置文件,MAPI 则显示选择配置文件对话框。单击新建以启动配置文件创建向导。
示例代码




// CreateProfileWithMAPILogonEx function: This takes advantage of the
// profile prompt dialog's "New" button.
bool CreateProfileWithMAPILogonEx()
{
HRESULT         hRes = S_OK;        // Return code from MAPI calls.
LPMAPISESSION   lpSession = NULL;   // MAPI Session pointer.
// Initialize MAPI.
if (FAILED(hRes = MAPIInitialize(NULL)))
{
cout<<"Error initializing MAPI. hRes = 0x"<<hex<<hRes<<dec<<endl;
return FALSE;
}
// Instruct user to click the "New" button.
cout<<"When the \"Choose Profile\" dialog appears, click the \"New\" button"
<<"to configure a new profile."<<endl;
// Call MAPILogonEx to display the profile chooser dialog.
if (FAILED(hRes = MAPILogonEx(NULL,
NULL,
NULL,
MAPI_LOGON_UI,
&lpSession)))
{
cout<<"Error logging on. hRes = 0x"<<hex<<hRes<<dec<<endl;
return FALSE;
}
// Log off the session.
if (FAILED(hRes = lpSession->Logoff(0,0,0)))
{
cout<<"Error logging off. hRes = 0x"<<hex<<hRes<<dec<<endl;
}
// Release the session.
lpSession->Release();
// Uninitialize MAPI.
MAPIUninitialize();
// Return true to indicate success.
return TRUE;
}


4. 使用 LAUNCHWIZARDENTRY 函数

该函数直接调用配置文件创建向导。
示例代码




// CreateProfileWithLAUNCHWIZARD function: This uses the LAUNCHWIZARDENTRY API
// to display the profile configuration UI.
bool CreateProfileWithLAUNCHWIZARD()
{
HRESULT     hRes = S_OK;                    // Return code from MAPI calls.
TCHAR       szProfName[80] = {0};           // String to hold profile name.
LPTSTR      szServices[] = {"MSEMS", NULL}; // String to hold message service names.
// Call LaunchWizard to add the MSEMS service.
if (FAILED(hRes = LaunchWizard(NULL,
NULL,
(LPCTSTR *)szServices,
80,
szProfName)))
{
cout<<"Error launching wizard. hRes = 0x"<<hex<<hRes<<dec<<endl;
return FALSE;
}
// Return true indicating success.
return TRUE;
}


5. 使用 MAPI IProfAdmin 接口

使用此 MAPI 接口,您可以在无用户干预的情况下以编程方式创建配置文件。
示例代码




// CreateProfileWithIProfAdmin function: This uses the MAPI IProfAdmin to
// programmatically create a profile. No UI is displayed.
bool CreateProfileWithIProfAdmin()
{
HRESULT         hRes = S_OK;            // Result from MAPI calls.
LPPROFADMIN     lpProfAdmin = NULL;     // Profile Admin object.
LPSERVICEADMIN  lpSvcAdmin = NULL;      // Service Admin object.
LPMAPITABLE     lpMsgSvcTable = NULL;   // Table to hold services.
LPSRowSet       lpSvcRows = NULL;       // Rowset to hold results of table query.
SPropValue      rgval[2];               // Property structure to hold values we want to set.
SRestriction    sres;                   // Restriction structure.
SPropValue      SvcProps;               // Property structure for restriction.
char            szProfile[80] = {0};    // String for profile name.
char            szMailbox[80] = {0};    // String for mailbox name.
char            szServer[80] = {0};     // String for server name.
// This indicates columns we want returned from HrQueryAllRows.
enum {iSvcName, iSvcUID, cptaSvc};
SizedSPropTagArray(cptaSvc,sptCols) = { cptaSvc, PR_SERVICE_NAME, PR_SERVICE_UID };
// Get configuration info from user.
cout<<"Enter name for profile: ";
cin>>szProfile;
cout<<"Enter Exchange mailbox name: ";
cin>>szMailbox;
cout<<"Enter Exchange server name: ";
cin>>szServer;
// Initialize MAPI.
if (FAILED(hRes = MAPIInitialize(NULL)))
{
cout<<"Error initializing MAPI.";
goto error;
}
// Get an IProfAdmin interface.
if (FAILED(hRes = MAPIAdminProfiles(0,              // Flags.
&lpProfAdmin))) // Pointer to new IProfAdmin.
{
cout<<"Error getting IProfAdmin interface.";
goto error;
}
// Create a new profile.
if (FAILED(hRes = lpProfAdmin->CreateProfile(szProfile,     // Name of new profile.
NULL,          // Password for profile.
NULL,          // Handle to parent window.
NULL)))        // Flags.
{
cout<<"Error creating profile.";
goto error;
}
// Get an IMsgServiceAdmin interface off of the IProfAdmin interface.
if (FAILED(hRes = lpProfAdmin->AdminServices(szProfile,     // Profile that we want to modify.
NULL,          // Password for that profile.
NULL,          // Handle to parent window.
0,             // Flags.
&lpSvcAdmin))) // Pointer to new IMsgServiceAdmin.
{
cout<<"Error getting IMsgServiceAdmin interface.";
goto error;
}
// Create the new message service for Exchange.
if (FAILED(hRes = lpSvcAdmin->CreateMsgService("MSEMS",     // Name of service from MAPISVC.INF.
NULL,        // Display name of service.
NULL,        // Handle to parent window.
NULL)))      // Flags.
{
cout<<"Error creating Exchange message service.";
goto error;
}
// We now need to get the entry id for the new service.
// This can be done by getting the message service table
// and getting the entry that corresponds to the new service.
if (FAILED(hRes = lpSvcAdmin->GetMsgServiceTable(0,                 // Flags.
&lpMsgSvcTable)))  // Pointer to table.
{
cout<<"Error getting Message Service Table.";
goto error;
}
// Set up restriction to query table.
sres.rt = RES_CONTENT;
sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;
sres.res.resContent.ulPropTag = PR_SERVICE_NAME;
sres.res.resContent.lpProp = &SvcProps;
SvcProps.ulPropTag = PR_SERVICE_NAME;
SvcProps.Value.lpszA = "MSEMS";
// Query the table to get the entry for the newly created message service.
if (FAILED(hRes = HrQueryAllRows(lpMsgSvcTable,
(LPSPropTagArray)&sptCols,
&sres,
NULL,
0,
&lpSvcRows)))
{
cout<<"Error querying table for new message service.";
goto error;
}
// Setup a SPropValue array for the properties you need to configure.
// First, the server name.
ZeroMemory(&rgval[1], sizeof(SPropValue) );
rgval[1].ulPropTag = PR_PROFILE_UNRESOLVED_SERVER;
rgval[1].Value.lpszA = szServer;
// Next, the mailbox name.
ZeroMemory(&rgval[0], sizeof(SPropValue) );
rgval[0].ulPropTag = PR_PROFILE_UNRESOLVED_NAME;
rgval[0].Value.lpszA = szMailbox;
// Configure the message service with the above properties.
if (FAILED(hRes = lpSvcAdmin->ConfigureMsgService(
(LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb, // Entry ID of service to configure.
NULL,                                                       // Handle to parent window.
0,                                                          // Flags.
2,                                                          // Number of properties we are setting.
rgval)))                                                    // Pointer to SPropValue array.
{
cout<<"Error configuring message service.";
goto error;
}
goto cleanup;
error:
cout<<" hRes = 0x"<<hex<<hRes<<dec<<endl;
return FALSE;
cleanup:
// Clean up.
if (lpSvcRows) FreeProws(lpSvcRows);
if (lpMsgSvcTable) lpMsgSvcTable->Release();
if (lpSvcAdmin) lpSvcAdmin->Release();
if (lpProfAdmin) lpProfAdmin->Release();
MAPIUninitialize();
return TRUE;
}



示例
从 Microsoft 下载中心可以下载以下文件:

Profiler.exe (http://download.microsoft.com/download/exchplatinumbeta/sample/1.0/nt45/en-us/profiler.exe)  
Profiler.exe 是一个简单的 Microsoft Visual C++ 示例,它演示了上面的方法 3 到方法 5。Profiler.exe 文件包含下列文件:






文件名大小


Profiler.dsw
1 KB


Profiler.dsp
5 KB


Profiler.cpp
12 KB

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-112872-1-1.html 上篇帖子: 无法启动microsoft office outlook 无法打开Outlook窗口 下篇帖子: 一次恢复outlook express通讯录文件*.wab的经历
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表