Outlook 2003自动配置文件配置 - 查询AD CN名称

Outlook 2003自动配置文件配置 - 查询AD CN名称

问题描述:

您好,首先我要道歉,如果这是错误的部分。

Hello, first of all I would like to apologise if this is in the wrong section.

 

我使用一个outlook自动配置脚本,用于在我的组织Domain上配置2003邮件配置文件,并且该脚本运行良好。我们最近使用单独的组织创建了一个林信任,但是当登录到受信任林中的计算机时,
脚本失败。我已经能够解决它失败的问题,但可以将代码拼凑起来解决问题。

I use an outlook automatic configuration script to configure 2003 mail profiles on my organisations Domain, and the script work well. We recently created a forest trust with a separate organisation but when logging onto a machine in the trusted forest the script fails. I’ve been able to work out where it’s failing, but can’t piece together the code to resolve the problem.

 

部分脚本检查用户是否已启用邮箱,并且此位失败。如果我在下面的代码中替换该行,请选择"设置objUser”使用
  “ LDAP:// cn =测试用户,OU =测试用户,dc = mydomain,dc = com"
 
可行。因此,我想知道是否有’为用户CN名称查询AD的方式?

Part of the script checks that the user is mailbox enabled and it’s this bit that fails. If I substitute the line in the code below starting “Set objUser” with  “LDAP://cn=test user,OU=Test Users,dc=mydomain,dc=com"  it works. Therefore I’m wondering if there’s a way to query AD for the users CN name?

 

'****** *****************************************

'***********************************************

'本节改编自:

'HasMailbox.vbs

' HasMailbox.vbs

'(c)2003 Computech

' (c) 2003 Computech

'由Peter Verijke撰写

' Written by Peter Verijke

'******************************** ***************

'***********************************************

 

 

如果ArgObj.Count< 1然后

If ArgObj.Count < 1 Then

   设置objEnv = WshShell.Environment(" PROCESS")

   Set objEnv = WshShell.Environment("PROCESS")

 

   sUserName = objEnv(" USERNAME")

   sUserName = objEnv("USERNAME")

   sLogonServer = objEnv(" LOGONSERVER")

   sLogonServer = objEnv("LOGONSERVER")

else

   sUserName = UCase(ArgObj(0))

   sUserName = UCase(ArgObj(0))

结束如果

 

DCServer = RmChr(sLogonServer," \")

DCServer = RmChr(sLogonServer, "\")

sUserLDAPName = QueryActiveDirectory(sUserName)

sUserLDAPName = QueryActiveDirectory(sUserName)

 

设置objUser = GetObject(" LDAP://"& DCServer +" /"& sUserLDAPName)

Set objUser = GetObject("LDAP://" & DCServer + "/" & sUserLDAPName)

 

设置objMailbox = objUser

Set objMailbox = objUser

'检查用户是否已启用邮箱

'check if user is mailbox enabled

如果objMailbox.HomeMDB =""然后

If objMailbox.HomeMDB = "" Then

   wscript.echo" No Mailbox - Quitting"

   wscript.echo "No Mailbox - Quitting"

   WScript.Quit 1

   WScript.Quit 1

否则

   wscript.echo"有邮箱"

   wscript.echo "Has Mailbox"

结束如果

 

&nbsp ;

感谢任何帮助。

 

谢谢,

 

Paul。

因此,我想知道是否有’为用户CN名称查询AD的方法?
Therefore I’m wondering if there’s a way to query AD for the users CN name?

确实有,但我认为你实际上是指 DN distinguishedName ),这是包括所有"CN"的整个字符串。 (COMMONNAME),QUOT;欧&QUOT; (organizationalUnit)
和"DC" (domainCoomponent)和其他适用的部分。

Indeed there is, though I think you actually mean DN (distinguishedName), which is the entire string including all the "CN" (commonName),"OU" (organizationalUnit) and "DC" (domainCoomponent), and other pieces as applicable.

要执行翻译,请使用
IADsNameTranslate对象
。您可以通过简单的WinNT名称(DOMAIN \USERNAME)来识别用户,您可以轻松地从环境变量中检索这些名称。这是一个只显示当前用户的完整DN的示例:

To perform the translations, use the IADsNameTranslate object. You can first identify the user by their simple WinNT name (DOMAIN\USERNAME), which you can easily retrieve from environment variables as you are already doing. Here's an example that just displays the current user's full DN:

Dim WshShell, objEnv
Dim uDomain, userWinNTName, userDN
Dim oNTranslate

'ADS_NAME_INITTYPE_ENUM: http://msdn.microsoft.com/en-us/library/aa772266(v=VS.85).aspx
const ADS_NAME_INITTYPE_DOMAIN  = 1
const ADS_NAME_INITTYPE_SERVER  = 2
const ADS_NAME_INITTYPE_GC    = 3 

' ADS_NAME_TYPE_ENUM: http://msdn.microsoft.com/en-us/library/aa772267(v=VS.85).aspx
const ADS_NAME_TYPE_1779 = 1  ' LDAP Distinguised Name, from RFC 1779
const ADS_NAME_TYPE_NT4 = 3
 
Set WshShell = CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("PROCESS")

uDomain = "some.example.com"
userWinNTName = objEnv("USERDOMAIN") & "\" & objEnv("USERNAME")
Set oNTranslate = CreateObject("NameTranslate")
oNTranslate.Init ADS_NAME_INITTYPE_DOMAIN, uDomain
oNTranslate.Set ADS_NAME_TYPE_NT4, userWinNTName
userDN = oNTranslate.Get(ADS_NAME_TYPE_1779)

MsgBox userWinNTName & " --> " & userDN