1

At work, we have short login names, e.g. hastingsg, but Outlook and I believe other parts of the Windows system also have access to a longer name, e.g. Jeff Hastings.

In cpython (not IronPython), if I have the shorter login name, how can I get the longer full name? I have pywin32 and ExchangeCDO installed.

4

3 回答 3

2

通过 的 COM 部分pywin32,您需要获取 Outlook 的 Application 对象,并从中获取它的属性Session,它为您提供Namespace对象(该GetNamespace方法也应该用于相同的目的,当使用唯一支持的参数值调用时'MAPI')。从那里,您可以使用该Accounts属性来获取Accounts对象,这是一个典型的 COM 集合——可通过ItemCount. 您遍历它并检查每个Account对象:每个都有两个感兴趣的属性——a UserName(您要检查与“较短的登录名”是否相等的字符串)和DisplayNamea——您想要的字符串。

是的,这非常长且令人费解,但是,这对于 MS 应用程序提供的 COM 接口课程来说是一样的。据我所知,在最近的 Outlook 版本中可能会有更精简的方式——这是长期以来一直在工作的漫长而复杂的方式(这些天我什至没有方便的 Windows 安装来检查这一点并编写 Python为你...!-)

于 2009-11-12T05:45:48.370 回答
1

我认为您可以使用专用模块查询您的 Exchange Server Active Directory

(未测试):

import active_directory
user = active_directory.find_user("hastingsg")
print user.displayName
于 2009-11-12T05:45:07.930 回答
0

可能你需要 TranslateName api 例如玩这样的东西,2ns /3rd 参数可以是来自http://msdn.microsoft.com/en-us/library/ms724268(VS.85).aspx的常量

win32security.TranslateName(win32api.GetUserName(), win32api.NameUnknown, win32api.NameDisplay)

或者

win32net.NetUseGetInfo(win32api.GetComputerName(),win32api.GetUserName())
于 2009-11-12T06:08:13.847 回答