Autor Beitrag
uranop
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 149

Win XP, Win 7, Slackware 11, FreeBSD
D6E, php
BeitragVerfasst: Do 28.08.08 07:21 
Guten morgen,
ich habe gestern von unseren oberen Server fuzzies nen vbs script bekommen um paar LDAP sachen zu zu lesen die ich benötige ....

Ich bin schon soweit, das ich mit das ADO teil ins form gezogen hbe mich per ms ole für directory services auf den AD server geklickt habe ...

nun muss ich nur noch an die entsprechenden werte kommen.

nur irgendwie habe ich da noch keine ahnung wo ich anfangen soll.

ich gebe euch mal nen auszug ausm qulltext des scriptes ...

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
'Define variables
Dim conn
Dim command
Dim rs
Dim objArgs
Dim NoGroups
Dim objNetwork

'Get active User
Set objNetwork = CreateObject("Wscript.Network")
txtUserID = objNetwork.UserName
txtDomain = objNetwork.UserDomain

'**Start Encode**

'Query the Global Catalog to find the user or group,
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADsDSOObject"
conn.open "DS Query"

set command=CreateObject("ADODB.Command")
set command.ActiveConnection = conn
command.CommandText = "<GC://dc=domain,DC=tld>;(cn="& txtUserID & ");cn,AdsPath;subTree"

set rs=CreateObject("ADODB.Recordset")
set rs=command.execute

If rs.RecordCount <> 1 Then
WScript.Echo "User could not be found."
WScript.Quit
End If

sUser=replace(rs("AdsPath"),"GC://","")
Set objUser=GetObject("LDAP://SERVER/" & sUser)
If Err.Number <> 0 Then
MsgBox err.number
End If
'**Stop Encode**

txtOutput = "Username : " & txtUserID & vbCrLf
txtOutput = txtOutput & "Display Name: " & objUser.displayName & vbCrLf
txtOutput = txtOutput & "Description : " & objUser.Description & vbCrLf
txtOutput = txtoutput & "Department : " & objUser.department & vbCrLf
txtOutput = txtOutput & "Domain: " & txtDomain & vbCrLf
txtOutput = txtOutput & "mail : " & objUser.mail & vbCrLf
txtOutput = txtOutput & "Home Drive: " & objUser.homeDrive & vbCrLf
txtOutput = txtOutput & "Home Drive Path: " & objUser.homeDirectory & vbCrLf
txtOutput = txtOutput & "Telefon : " & objUser.telephoneNumber & vbCrLf
txtOutput = txtOutput & "Kostenstelle : " & objUser.rocheLocalCostCenter


MsgBox txtOutput

Set objNetwork=Nothing
Set conn=Nothing
Set command=Nothing
Set rs=Nothing


also diese doofe msg box will ich natuerlich nicht sondern schon da oben die objUser daten in Edit fields schmeissen...

kann mir wer etwas auf die sprünge helfen ?
uko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 220
Erhaltene Danke: 1

Win XP, VISTA, WIndows 7
Delphi 2007/2010 Prof
BeitragVerfasst: Do 28.08.08 09:31 
uranop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 149

Win XP, Win 7, Slackware 11, FreeBSD
D6E, php
BeitragVerfasst: Do 28.08.08 15:41 
in ansaetzen gehts scho nweiter. allerdings komm ich noch nicht auf den tricher wie ich die "SQL" abfrage da gestellten soll weil die strucktur von vb mit ldap mir voellig fremd is
uko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 220
Erhaltene Danke: 1

Win XP, VISTA, WIndows 7
Delphi 2007/2010 Prof
BeitragVerfasst: Do 28.08.08 16:03 
Dann geh halt anders ran: versuch mittels der beiden Links zu verstehen, wie man AD / LDAP anspricht. Und dann laß Dir von jemanden erklären, wie man die fachlichen Daten erhält (ohne Kenntnise von LDAP / AD / VB würd ich jetzt sagen, daß der erste Teil des Scripts sich mit AD connected und den aktuellen User ausliest. Anschliessend werden für diesen User die Daten aus den zugehörigen User-Objekt gelesen). Und das programmier dann nach. :-)

Grüße,
Uli
uranop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 149

Win XP, Win 7, Slackware 11, FreeBSD
D6E, php
BeitragVerfasst: Sa 30.08.08 14:11 
aus der DP ( >> www.delphipraxis.net/post866363.html ) hab ich bissl was aufgeschnappt,
allerdings steh ich nun vor nem raetsel

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
procedure TForm1.Button1Click(Sender: TObject);
var
conn,com,rs: variant;
sUser,txtUser,txtDomain: string;
begin
  conn := CreateOleObject('ADODB.Connection');
  com := CreateOleObject('ADODB.Command');
  try
    conn.Provider := 'ADsDSOObject';
    conn.open;
    com.ActiveConnection := conn;
    txtUser := Edit1.Text;
    com.CommandText :='<LDAP://SERVER>;cn=' + txtUser + ';cn,AdsPath,subtree';

    com.Properties['Page Size'] := 100000;
    com.Properties['Searchscope'] := 2;
    com.Properties['Cache Results'] := False;
    rs := com.Execute;                                   // hier bleibt der debugger stehen
if Not rs.EOF then
    begin
    Edit2.Text := txtUser;
    Edit3.Text := rs.Fields['displayName'].Value;
    Edit4.Text := rs.Fields['description'].Value;
    Edit5.Text := rs.Fields['department'].Value;
    Edit6.Text := 'bla';
    Edit7.Text := rs.Fields['mail'].Value;
    Edit8.Text := rs.Fields['homeDrive'].Value;
    Edit9.Text := rs.Fields['homeDirectory'].Value;
    Edit10.Text := rs.Fields['telephoneNumber'].Value;
    Edit11.Text := rs.Fields['rocheLocalCostCenter'].Value;
    end
else
      MessageDlg('Kein Datensatz gefunden.',mtInformation,[mbOK],0);
    Rs := NULL;
  finally
    com := NULL;
    conn.Close;
    conn := NULL;
  end;
end;


ich bekomm nun immer
user defined image

:haarerauf: