#198418 - 2010-04-20 07:46 PM
ADS Obj with KIX.... Please help!!!
|
peacey
Fresh Scripter
Registered: 2010-02-02
Posts: 20
Loc: Nottingham, UK
|
Hi there,
I'm trying to find out how to set the ADSobject in my Kix Script so that get / read the adsObj.HomeDirectory from the Active directoy as I want to map users personal drives within their Citrix Session. here is the VBS Script used in a previous script with NT4 Domain.
adsPath = "WinNT://" & strDomain & "/" & strUser Set adsObj=GetObject(adsPath) strHomeDIR = adsObj.HomeDirectory
Sub MapDrives()
Call FuncMapDrive("P:", strHomeDIR)
Is such a thing possible in KIX?
Please help!!!!
Regards
Richard
|
|
Top
|
|
|
|
#198419 - 2010-04-20 08:34 PM
Re: ADS Obj with KIX.... Please help!!!
[Re: peacey]
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
$adsPath = "WinNT://" + $strDomain + "/" + $strUser
$adsObj=GetObject($adsPath)
$strHomeDIR = $adsObj.HomeDirectory
goSub MapDrives()
FuncMapDrive("P:", strHomeDIR)
You missing a few odd's and ends like the variables $strDomain and $strUser....
the last 2 lines.... refer to other parts of the script... so... i took my best guess.
|
|
Top
|
|
|
|
#198421 - 2010-04-21 11:17 AM
Re: ADS Obj with KIX.... Please help!!!
[Re: Mart]
|
peacey
Fresh Scripter
Registered: 2010-02-02
Posts: 20
Loc: Nottingham, UK
|
Guys this is magic stuff. the varibles in the VB script are:
strUser = WSHNetwork.UserName strDomain = WSHNetwork.UserDomain
What would this be the same for AD and within the KIX script?
Could you decode this for me please??
Regards
Richard
|
|
Top
|
|
|
|
#198422 - 2010-04-21 01:21 PM
Re: ADS Obj with KIX.... Please help!!!
[Re: peacey]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
$adsPath = "WinNT://" + @DOMAIN + "/" + @USERID
$adsObj=GetObject($adsPath)
$strHomeDIR = $adsObj.HomeDirectory
"My home directory is : "+$strHomeDir+@CRLF
"...or with built-in macros: "+@HOMESHR+"\"+@HOMEDIR+@CRLF
"...or more simply: "+%HOMESHARE%+@CRLF
|
|
Top
|
|
|
|
#198423 - 2010-04-21 01:58 PM
Re: ADS Obj with KIX.... Please help!!!
[Re: Richard H.]
|
peacey
Fresh Scripter
Registered: 2010-02-02
Posts: 20
Loc: Nottingham, UK
|
Thanks Richard for your quick reply, but for some reason it's ust picking up the Terminal Service Homeshare which is already mapped as part of my Group policy (H:\), I need the script to pickup the share from the Profile AD tab (Which is a P:\ (Differnt Server) not Terminal Service Home Drive. This is the dive which gets mapped when they login to there desktop / laptop, but I want to mapp it into there Citrix Session using my Citrix Kix logon script.
Any thought?
Richard
Edited by peacey (2010-04-21 01:58 PM)
|
|
Top
|
|
|
|
#198425 - 2010-04-21 02:18 PM
Re: ADS Obj with KIX.... Please help!!!
[Re: Richard H.]
|
peacey
Fresh Scripter
Registered: 2010-02-02
Posts: 20
Loc: Nottingham, UK
|
Ha ha Sorry!
OK, when I try and Run the Script with the Code given above. I can see that it is trying to display the Terminal Server Home Directory . I need to map to the Home Directory.
These are seperate Attribute names in AD
It's just confusing me out!
Rich
Edited by peacey (2010-04-21 02:18 PM)
|
|
Top
|
|
|
|
#198426 - 2010-04-21 03:59 PM
Re: ADS Obj with KIX.... Please help!!!
[Re: peacey]
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Below is an example of how to get the data from AD. It list the most common (if not all) attributes for the current user. The regular home folder and the TS home folder are indeed different attributes. The script above should show the regular home directory and not the TS version.
What does the script below show at both home directory paths?
CLS
Break on
$username = @USERID
$userhome = TranslateName(3, "", 3, @LDomain + "\" + $username, 1)
$userinfo = GetObject("LDAP://" + $userhome[0])
? "General Info"
? "------------"
? " "
? "First Name: " + $userinfo.givenName
? "Initials: " + $userinfo.initials
? "Last Name: " + $userinfo.sn
? "Full Name: " + $userinfo.FullName
? "Display Name: " + $userinfo.displayName
? "Account Name: " + $userinfo.sAMAccountName
? "Distinguished Name: " + $userinfo.distinguishedName
? "Description: " + $userinfo.Description
? "Office Location: " + $userinfo.physicalDeliveryOfficeName
? "Email: " + $userinfo.mail
? "Web Page: " + $userinfo.wwwHomePage
? "Street: " + $userinfo.streetAddress
? "Postal Code: " + $userinfo.postalCode
? "Post Office Box: " + $userinfo.postOfficeBox
? "City: " + $userinfo.l
? "State or Province: " + $userinfo.st
? "Country or Region: " + $userinfo.co
? "Home Phone: " + $userinfo.homePhone
? "Pager: " + $userinfo.pager
? "Mobile Phone: " + $userinfo.mobile
? "Telephone Number: " + $userinfo.telephoneNumber
? "Fax Number: " + $userinfo.facsimileTelephoneNumber
? "Notes: " + $userinfo.info
? "Title: " + $userinfo.title
? "Department: " + $userinfo.department
? "Company Name: " + $userinfo.company
? "Principal Name: " + $userinfo.userPrincipalName
? " "
? "Profile Info"
? "------------"
? " "
? "Profile Path: " + $userinfo.profilePath
? "Script Path: " + $userinfo.scriptPath
? "Home Directory: " + $userinfo.homeDirectory
? "Home Drive: " + $userinfo.homeDrive
? "Terminal Services Profile Path: " + $userinfo.TerminalServicesProfilePath
? "Terminal Services Local Path: " + $userinfo.TerminalServicesHomeDirectory
? "Terminal Services Home Drive: " + $userinfo.TerminalServicesHomeDrive
? "Terminal Services Allowed: " + $userinfo.AllowLogon
? " "
? "Account Info"
? "------------"
? " "
? "User Account Control: " + $userinfo.userAccountControl
? "Account Disabled: " + $userinfo.AccountDisabled
? "Account Locked: " + $userinfo.IsAccountLocked
? "Account Created: " + $userinfo.whenCreated
? "Account Last Modified: " + $userinfo.whenChanged
? "Account Expires: " + $userinfo.AccountExpirationDate
? "Last Login: " + $userinfo.LastLogin
? "Last Failed Login: " + $userinfo.LastFailedLogin
? "Logon Count: " + $userinfo.logonCount
? "Bad Login Count: " + $userinfo.BadLoginCount
? "Password Last Changed: " + $userinfo.PasswordLastChanged
? 'Press a key...'
Get $
; TranslateName function authored by Howard A. Bullock
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
I found this code some time ago on this board. Don’t know who posted it but so far is was worth its weight in gold for me. Helped me out more then once.
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
|
Top
|
|
|
|
#198427 - 2010-04-21 05:34 PM
Re: ADS Obj with KIX.... Please help!!!
[Re: Mart]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
The following udf should do what you want:
GetADUserProperties() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=194576#Post194576
Paste the UDF to the bottom of your script. Not sure which attribute you need, but something like this
$hdir=GetADUserProperties("HomeDirectory")
$hfol=GetADUserProperties("HomeDrive")
? $hdir
? $hfol
|
|
Top
|
|
|
|
#198428 - 2010-04-21 06:05 PM
Re: ADS Obj with KIX.... Please help!!!
[Re: Allen]
|
peacey
Fresh Scripter
Registered: 2010-02-02
Posts: 20
Loc: Nottingham, UK
|
Guys this is brilliant!
I will test this out and come back with my findings!
Thanks Again
Richard
|
|
Top
|
|
|
|
#198429 - 2010-04-21 06:34 PM
Re: ADS Obj with KIX.... Please help!!!
[Re: peacey]
|
peacey
Fresh Scripter
Registered: 2010-02-02
Posts: 20
Loc: Nottingham, UK
|
Ok... Being really stupid now because I don't know what funtion to use after the script gets the AD Properties I am asking for...
I really like the Funcmapdrive stuff but cannot get it to work. Any thoughts
here is the test script:
Select Case @INWIN = ("1") ;Windows NT
$adsPath = "WinNT://" + @DOMAIN + "/" + @USERID $adsObj=GetObject($adsPath)
$hdir=GetADUserProperties("HomeDirectory")
FuncMapDrive("P:", $hdir)
Endselect
Thanks
Richard
|
|
Top
|
|
|
|
#198434 - 2010-04-22 07:59 PM
Re: ADS Obj with KIX.... Please help!!!
[Re: Richard H.]
|
peacey
Fresh Scripter
Registered: 2010-02-02
Posts: 20
Loc: Nottingham, UK
|
Can anyone tell me what is in the @HOMESHR macro?
Edited by Richard H. (2010-04-23 11:34 AM) Edit Reason: Oops. Edited OP post.
|
|
Top
|
|
|
|
#198440 - 2010-04-23 11:37 AM
Re: ADS Obj with KIX.... Please help!!!
[Re: peacey]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Sorry Richard, I edited your post by mistake instead of responding.
There is a section in the manual that defines all the available macros. Have a read as there may be something else that can help you out.
Macros simply return strings, so you can just disply them to see their content. If you look up a couple of posts you'll see I did exactly that earlier, but here it is again on it's own:
"HOMESHR macro value="+@HOMESHR+@CRLF
Now, @HOMESHR is probably not going to do what you want. When you log in using Citrix @HOMESHR is going to contain the TS home share, which is not what you want. You want to map the non-TS home share to P: if I understand correctly.
Try this script which will show the path from AD and the path from @HOMESHR. I expect that this should be different if you use different home directories for standard vs terminal server logins.
"Home Directory from @@HOMESHR macro="+@HOMESHR+@CRLF
" Home Directory from AD object="+GetObject("WinNT://"+@LDOMAIN+"/"+@USERID).HomeDirectory+@CRLF
@CRLF+"Hit a key to exit: " Get $ @CRLF
FlushKB()
|
|
Top
|
|
|
|
#198630 - 2010-05-16 08:50 AM
Re: ADS Obj with KIX.... Please help!!!
[Re: Arend_]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
I did write one to enumerate all entries, but can't find it in my repository, once I do I'll post it.
[Update] Found it, it's a quick way so no code complaints :P This enumerates all ADSI properties of an object to a text file.
ListAdsiToTxt("MyDomain\MyGroup","@SCRIPTDIR\group.txt")
ListAdsiToTxt("MyDomain\MyUser","@SCRIPTDIR\user.txt")
ListAdsiToTxt("MyDomain\MyComputer$","@SCRIPTDIR\computer.txt")
Function ListAdsiToTxt($usr, $logf)
Global $log
Dim $cnusr, $usrnfo, $usrclas, $fso, $prop
$cnusr = TranslateName($usr)
$usrnfo = GetObject("LDAP://" + $cnusr)
$usrclas = GetObject($usrnfo.schema)
$fso = CreateObject("Scripting.FileSystemObject")
$log = $fso.OpenTextFile($logf, 8, 1)
$log.WriteLine("Mandatory Properties:")
$log.WriteLine("---------------------")
$log.WriteLine("")
For Each $prop in $usrclas.MandatoryProperties
If NOT Instr($prop,"-")
$=Execute("$$Type=VarTypeName($$usrnfo."+$prop+")")
$=Execute("$$Value=$$usrnfo."+$prop)
$s = ""
Select
Case $type = "Object"
WriteLog($prop,$type)
Case $type = "Variant[]"
WriteLog($prop,$type)
For Each $item in $value
WriteLog("*"+$prop,$type,$item)
Next
Case $type = "Byte[]"
$comma = ""
For $i=0 to Len($value)
$s=$s+$comma+Right("0"+DecToHex(Asc(SubStr($value,$i,1))),2)
$comma = ","
Next
WriteLog($prop,$type,$s)
Case 1
WriteLog($prop,$type,$value)
EndSelect
Else
WriteLog($prop,"N/A")
EndIf
Next
$log.WriteLine("")
$log.WriteLine("Optional Properties:")
$log.WriteLine("--------------------")
$log.WriteLine("")
For Each $prop in $usrclas.OptionalProperties
If NOT Instr($prop,"-")
$= Execute("$$Type=VarTypeName($$usrnfo."+$prop+")")
$= Execute("$$Value=$$usrnfo."+$prop)
$s = ""
Select
Case $type = "Object"
$objDate = Integer8Date($value)
WriteLog($prop,$type,$objdate)
Case $type = "Variant[]"
WriteLog($prop,$type)
For Each $item in $value
WriteLog("*"+$prop,$type,$item)
Next
Case $type = "Byte[]"
$comma = ""
For $i=0 to Len($value)
$s=$s+$comma+Right("0"+DecToHex(Asc(SubStr($value,$i,1))),2)
$comma = ","
Next
WriteLog($prop,$type,$s)
Case 1
WriteLog($prop,$type,$value)
EndSelect
Else
WriteLog($prop,"N/A")
EndIf
Next
$log.Close
EndFunction
Function WriteLog($LineToWrite,$sType,Optional $sValue)
Select
Case Len($sType) < 9
$sType = $sType+Chr(9)+Chr(9)
Case Len($sType) >= 9
$sType = $sType+Chr(9)
Case 1
? "Other Type?"
EndSelect
Select
Case LEN($LineToWrite) < 8
$log.WriteLine($LineToWrite+Chr(9)+Chr(9)+Chr(9)+Chr(9)+Chr(9)+$sType+$sValue)
Case LEN($LineToWrite) >= 8 AND LEN($LineToWrite) < 16
$log.WriteLine($LineToWrite+Chr(9)+Chr(9)+Chr(9)+Chr(9)+$sType+$sValue)
Case LEN($LineToWrite) >= 16 AND LEN($LineToWrite) < 24
$log.WriteLine($LineToWrite+Chr(9)+Chr(9)+Chr(9)+$sType+$sValue)
Case LEN($LineToWrite) >= 24 AND LEN($LineToWrite) < 32
$log.WriteLine($LineToWrite+Chr(9)+Chr(9)+$sType+$sValue)
Case LEN($LineToWrite) >= 32
$log.WriteLine($LineToWrite+Chr(9)+$sType+$sValue)
Case 1
? "Other Len?"
EndSelect
EndFunction
Function TranslateName($NameToTranslate)
Dim $NameTranslate
$NameTranslate = CreateObject("NameTranslate")
$NameTranslate.Init(3,"")
$NameTranslate.Set(3,$NameToTranslate)
$TranslateName = $NameTranslate.Get(1)
EndFunction
Function Integer8Date($objDate,optional $lngBias)
Dim $lngHigh,$lngLow,$lngDate,$Pow,$l,$jdate,$lngYear,$lngMonth,$lngDay,$s,$m,$h
If Not (VarType($objDate) & 9) Exit 87 EndIf
If VarType($lngBias)=0
$lngBias = Val(ReadValue("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\","ActiveTimeBias"))
If @ERROR Exit @ERROR EndIf
EndIf
$lngHigh = $objDate.HighPart
$lngLow = $objDate.LowPart
If $lngLow < 0 $lngHigh=$lngHigh+1 EndIf
If $lngHigh = 0 And $lngLow = 0 $lngBias=0 EndIf
$Pow=2.0
For $l = 1 to 31 $Pow=2.0*$Pow Next
$lngDate = ((CDBL($lngHigh)*$Pow+$lngLow)/600000000-$lngBias)/1440
If $lngDate > 0
$jdate = 584389 + Fix($lngDate)
$lngYear = (100*(((100*($jdate+306)-25)/3652425)-(((100*($jdate+306)-25)/3652425)/4))+
(100*($jdate+306)-25))/36525
$lngMonth = (5*(((100*($jdate+306)-25)/3652425)-(((100*($jdate+306)-25)/3652425)/4)+
($jdate+306)-365*$lngYear-$lngYear/4)+456)/153
$lngDay = (((100*($jdate+306)-25)/3652425)-(((100*($jdate+306)-25)/3652425)/4)+
($jdate+306)-365*$lngYear-$lngYear/4)-(153*$lngMonth-457)/5
If $lngMonth>12 $lngYear=$lngYear+1 $lngMonth=$lngMonth-12 EndIf
$lngMonth = Right("0"+$lngMonth,2)
$lngDay = Right("0"+$lngDay,2)
$s = Fix(86400.0 * ($lngDate-Fix($lngDate)))
$m = $s / 60
$s = $s mod 60
$h = $m / 60
$m = $m mod 60
$Integer8Date=''+$lngYear+'/'+$lngMonth+'/'+$lngDay+' '+$h+':'+Right("0"+$m,2)+':'+Right("0"+$s,2)
EndIf
EndFunction
Edited by apronk (2010-05-16 09:00 AM) Edit Reason: Updated with code
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 977 anonymous users online.
|
|
|