Page 1 of 1 1
Topic Options
#135870 - 2005-03-17 12:05 PM search in active directory.
isotonic_uk Offline
Fresh Scripter

Registered: 2004-08-04
Posts: 7
Hi,

I have my form running but I want the user to be able to do the following in KIX.

Is it possible to do a search in active directory using display name of the target to confirm the username of the target via kix.

So far the form will allow me to put in students username and I connect to their share.

thanks

Break on
setconsole("hide")

Code:
 $Form = CreateObject("kixtart.Form") 
$Form.Size = 350,350
$Form.Text = "Accessing Home Directories -By S. Wintle"
$Form.BackColor = 186,218,240
$TextBox = $Form.TextBox("",120,100,80,20)

$label = $form.label("Please Type In Students Username.",20,10,150,30)

$Button1 = $Form.Button("Connect",100,150,120,40)
$Button2 = $Form.Button("Back To Main Menu",100,200,120,40)
$ExitButton = $Form.Button("Exit", 100,250,120,40)

$Button1.onclick = "Button1_CLick()"
$Button2.onclick = "Button2_CLick()"
$ExitButton.OnClick = "quit()"

$Form.Center
$Form.Show

while $Form.Visible
$=Execute($Form.DoEvents)
Loop
Quit()

Function Button1_Click

$user = $TextBox.value + "$"

use I: /del
use I: "\\curricsvr1\" + $user

if not @error
run "explorer i:\"
endif
EndFunction




_________________________
IT Kings Norton Girls School

Top
#135871 - 2005-03-17 02:12 PM Re: search in active directory.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
How about the TranslateName() UDF?
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=82426

Otherwise, the ADODB method should work. Try searching the board for examples.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135872 - 2005-03-22 10:39 AM Re: search in active directory.
isotonic_uk Offline
Fresh Scripter

Registered: 2004-08-04
Posts: 7
Hi,

Ive had a look at the UDF and cant figure out how it might be used in a script (doh!) Could you give some pointers perhaps. I need to convert from either display name in AD or @fullname to useename. Help is always much appreciated.

thanks

Ranj
_________________________
IT Kings Norton Girls School

Top
#135873 - 2005-03-23 03:30 PM Re: search in active directory.
isotonic_uk Offline
Fresh Scripter

Registered: 2004-08-04
Posts: 7
Hi,

Ive tried the following to get a return of the display name of a users details, but the UDF just returns the Domain name of our network. I'm doing something wrong can anybody help?

Cheers

Code:
 Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)

Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
Dim $NameTranslate, $ReturnName, $Error, $ErrorText

$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CREATEOBJECT ("NameTranslate")
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Init ($InitType, $BindName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$ReturnName = $NameTranslate.Get($ReturnNameType)
$Error = @error
$ErrorText = @serror
endif
endif
endif
$TranslateName = $ReturnName, $Error, $ErrorText
Endfunction

$DN = TranslateName (3, "KINGSNORTONGIRL\Jessica Bowen", 3, "@LDomain\@userid", 1)
? "DN = " + $DN[0]
? "Error = " + $DN[1]
? "ErrorText = " + $DN[2]

_________________________
IT Kings Norton Girls School

Top
#135874 - 2005-03-23 09:48 PM Re: search in active directory.
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
This function does not process display names. Please see the examples that are in the UDF header. I think that you would have to use ADO to query for the display name.


If you run these examples you will see what the UDF does.Code:

$DN = TranslateName (3, "", 3, "@Domain\@wksta$", 1)
? "DN = " + $DN[0]
? "Error = " + $DN[1]
? "ErrorText = " + $DN[2]

$DN = TranslateName (3, "", 3, "@LDomain\@userid", 1)
? "DN = " + $DN[0]
? "Error = " + $DN[1]
? "ErrorText = " + $DN[2]


_________________________
Home page: http://www.kixhelp.com/hb/

Top
#135875 - 2005-03-23 10:31 PM Re: search in active directory.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
So... the liner notes then are just wishful thinking?

; 4 = ADS_NAME_TYPE_DISPLAY
; Display name format. For example, "Jane Doe".
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135876 - 2005-03-23 10:55 PM Re: search in active directory.
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Crap!! I did not even read my own notes.


Let me test here...
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#135877 - 2005-03-23 11:08 PM Re: search in active directory.
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Well I was mostly right for this request.

Code:

$UserDistinguishedName = TranslateName (1, "domain", 4, "Bullock, Howard A.", 1)[0]
? "DN="+$UserDistinguishedName

$ADS_NAME_TYPE_DISPLAY = TranslateName (1, "domain", 3, "domain\user1", 4)[0]
? $ADS_NAME_TYPE_DISPLAY
exit 1




I examined and copied my "displayName" from the AD using LDP.exe to be sure that I got it correctly for input.

Translating from (3) ADS_NAME_TYPE_NT4 to (4) ADS_NAME_TYPE_DISPLAY works but the reverse does not. the code samples above show this.

This is documented somewhat in ...

;REMARKS Not all name types seem to work.

Top
#135878 - 2005-03-23 11:56 PM Re: search in active directory.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK, I'll let you off with a warning this time.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135879 - 2005-03-24 12:51 PM Re: search in active directory.
isotonic_uk Offline
Fresh Scripter

Registered: 2004-08-04
Posts: 7
Hi Les & Howard,

Many thanks for your help I have got the script to translate a display name to return the username, however it also returns the DNS and seems to suppress the zero at the beginning of the username.

Code:
$UserDistinguishedName = TranslateName (1, "kingsnortongirl", 4, "VICTORIA BENNETT", 1)[0]
? $UserDistinguishedName


returns

Code:
 C=uk2BenneT,OU=Curriculum2002,OU=Curriculum,DC=kingsnortongirls,DC=bham,DC=sch,D



Is there a way I can just display the username and not all of the OU and domain info? (the 2bennet bit is the usename returned successfully!)

Cheers

Ranj.
_________________________
IT Kings Norton Girls School

Top
#135880 - 2005-03-24 03:09 PM Re: search in active directory.
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
How does that work for you and does not work for me... More testing later today...


By changing the the last number in the call "1" to a "3" you should get the domain\user NT4 name. You could then split on "\" to return domain and user. Or you can just parse the DN you have. Use LEFT, Substr, Split, etc.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#135881 - 2005-04-13 02:31 PM Re: search in active directory.
isotonic_uk Offline
Fresh Scripter

Registered: 2004-08-04
Posts: 7
Hi,

Thanks for all of your replies, I have got a little further with this problem, using kix & forms we want our Teachers that dont know a pupils username to be able to type the display name int my form and this returns 'username' so with the UDF above the following script, Code:
Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)

Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
Dim $NameTranslate, $ReturnName, $Error, $ErrorText

$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CREATEOBJECT ("NameTranslate")
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Init ($InitType, $BindName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$ReturnName = $NameTranslate.Get($ReturnNameType)
$Error = @error
$ErrorText = @serror
endif
endif
endif
$TranslateName = $ReturnName, $Error, $ErrorText
Endfunction

$UserDistinguishedName = TranslateName (1, "kingsnortongirl", 4, "VICTORIA BENNETT", 3)[0]
? $UserDistinguishedName
exit 1



Then returns Code:
KINGSNORTONGIRL\02BenneV


(Thanks Howard)

This is my form/script uptill now, Code:
$Form = CreateObject("kixtart.Form") 
$Form.Size = 255,400
$Form.Text = "Accessing Home Directories -By S. Wintle"
$Form.BackColor = 186,218,230
$TextBox = $Form.TextBox("", 110,70,90,20)
$TextBox1 = $Form.TextBox("", 110,105,90,20)

$label = $form.label("Please Type In Students Username.",20,60,80,40)
$label1 = $form.label("Else type fullname.",20,105,80,40)

$Button = $Form.Button("Get user",70,170,120,40)
$Button1 = $Form.Button("Connect",70,220,120,40)
$Button2 = $Form.Button("Back To Main Menu",70,270,120,40)
$ExitButton = $Form.Button("Exit", 70,320,120,40)

$fraBanner = $FORM.PictureBox
$fraBanner.BACKCOLOR = $FORM.RGB(255,255,255)
$fraBanner.HEIGHT = 30
$fraBanner.LEFT = 7
$fraBanner.TOP = 10
$fraBanner.WIDTH = 230

$fraBanner.FONTSIZE = 14
$fraBanner.FONTNAME = "verdana"
$fraBanner.ForeColor = 0
$fraBanner.PrintXY(0,0,"Home Directories")

$Button.onclick = "Button_Click()"
$Button1.onclick = "Button1_CLick()"
$Button2.onclick = "Button2_CLick()"
$ExitButton.OnClick = "quit()"

$Form.Center
$Form.Show

while $Form.Visible
$=Execute($Form.DoEvents)
Loop
Quit()

Function Button_Click

$dspname = $TextBox1.Text
$UserDistinguishedName = TranslateName (1, "kingsnortongirl", 4, $dspname, 3)[0]
;? $UserDistinguishedName

$UserDistinguishedName = $TextBox.Text

EndFunction

Function Button1_Click

$user = $TextBox.value + "$"

use I: /del
use I: "\\curricsvr1\" + $user

if not @error
run "explorer i:\"
endif
EndFunction



As you can see I want the output of '$UserDistinguishedName' to appear in my text box. Cleary i'm doing sonmething wrong! Heellppp!

Cheers

Ranj.
_________________________
IT Kings Norton Girls School

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.06 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org