关于active directory的问题
1
[color=褐]
# ------ SCRIPT CONFIGURATION ------
my $strBase = "<LDAP://dc=coe,dc=ads>;"; # BaseDN should be the search base
my $strFilter = "(&(objectCategory=user)(ObjectClass=user)(samAccountName=raylin));";
# Valid LDAP search filter
my $strAttrs = "displayname;"; # Comma-seperated list
my $strScope = "subtree"; # Should be on of Subtree, Onelevel or Base
# ------ END CONFIGURATION ---------
use Win32::OLE;
$Win32::OLE::Warn = 3;
my $objConn = Win32::OLE->CreateObject("ADODB.Connection");
$objConn->{Provider} = "ADsDSOObject";
$objConn->Open;
my $objRS = $objConn->Execute($strBase . $strFilter . $strAttrs . $strScope);
print $objRS->Fields(0)->Value,"\n";
[/color]
要用一个用户名 “raylin” 去连接active directory, return 这个用户名在active directory 的 displayname。 如果这个用户名在ad不存在的话, 这段 coding就报错
[color=red]OLE exception from "ADODB.Field":
Either BOF or EOF is True, or the current record has been deleted. R
operation requires a current record.
Win32::OLE(0.1701) error 0x800a0bcd
in METHOD/PROPERTYGET "Value" at c:\perl\scripts\tt.pl line 17[/color]
怎样才能检查是否存在并给出自己的报错信息呢?
有一段vbscript好像就是关于这个的, 可是我不会把它转换成perl。
[code]
strUserName = "kenmyer"
dtStart = TimeValue(Now())
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://dc=fabrikam,dc=com>;(&(objectCategory=User)" & _
"(samAccountName=" & strUserName & "));samAccountName;subtree"
Set objRecordSet = objCommand.Execute
If objRecordset.RecordCount = 0 Then
WScript.Echo "sAMAccountName: " & strUserName & " does not exist."
Else
WScript.Echo strUserName & " exists."
End If
objConnection.Close
[/code]
大虾们帮帮忙, 小弟是新手, 弄不出来这个, 天天被老板骂。。。。