简体   繁体   English

在.NET中使用MAPI时如何处理用户访问控制

[英]How to handle User Access Control when using MAPI in .NET

I've used MAPI to create emails with attachments from my application and it works very well on XP and Vista (without UAC). 我已经使用MAPI从应用程序中创建带有附件的电子邮件,它在XP和Vista(不带UAC)上都可以很好地工作。 Of course, if you have UAC enabled, it just doesn't work (though it gives no errors, and doesn't prompt the user for permission to continue). 当然,如果您启用了UAC,它将无法正常工作(尽管它没有错误,并且不会提示用户继续操作的权限)。

I've done a bunch of reading and have found a lot of differing ideas: 我读了很多书,发现了很多不同的想法:

  • Require Admin privileges for the app 需要应用程序的管理员权限
  • Require some form of elevated privileges for the app 需要某种形式的提升权限的应用程序
  • Create a COM object for the small portions of code that require elevation 为需要提升代码的一小部分创建一个COM对象
  • Get the OS to prompt the users asking them if they want to continue. 获取操作系统以提示用户询问他们是否要继续。

I'm wondering what SO Users would do given that I really only need elevation for one or two functions. 考虑到我真的只需要提升一个或两个功能,我想知道SO用户会怎么做。 I'm looking for the minimal amount of pain here (I don't do COM, but I can P/Invoke with the best of them...), and I'm working in .NET 2.0 (it's a legacy app). 我正在这里寻求最小的痛苦(我不做COM,但是我可以用他们中的最好的来P / Invoke ...),并且我正在.NET 2.0(这是一个遗留应用程序)中工作。

EDIT: I agree that elevating the whole app isn't a great idea given that only part of it needs the eleveation, but my thought had been that might be easier in the long run than trying to elevate only part of it. 编辑:我同意提升整个应用程序不是一个好主意,因为只有一部分需要进行升级,但是从长远来看,我认为比尝试仅提升一部分应用程序要容易得多。

Also, I'd rather stay away from the .NET SMTP solution, since my goal is simply to create a message and with an attachment, but display it to the user so that they can add more text and send it at their leisure... 另外,我宁愿不使用.NET SMTP解决方案,因为我的目标只是创建一条消息并带有附件,而是将其显示给用户,以便他们可以添加更多文本并在闲暇时发送。 。

If you can give up MAPI in favor of the more general SMTP , you can use .NET's System.Net.Mail.SmtpClient class. 如果您可以放弃MAPI而使用更通用的SMTP ,则可以使用.NET的System.Net.Mail.SmtpClient类。 Together with the MailMessage class, you can add attachments and send messages via any willing SMTP server. MailMessage类一起,您可以添加附件并通过任何愿意使用的SMTP服务器发送邮件。

All available in good old .NET 2.0 as managed code - no need for p/invoke or COM. 所有这些都可以在良好的旧版.NET 2.0中作为托管代码使用-无需p / invoke或COM。 Examples in the referenced pages. 参考页面中的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM