#172841 - 2007-01-16 07:06 PM
Enter registry key, based on info from AD - but with a twist?
|
jon
Fresh Scripter
Registered: 2007-01-15
Posts: 11
|
My previous posts have got me to this stage which is good but I wonder if there is some further way of automation? http://www.kixtart.org/forums/ubbthreads...true#Post172805
IF @WKSTA="TS-SERVER" $User=ReadValue('HKEY_CURRENT_USER\Software\GoldMine\GoldMine Link for Microsoft Outlook','GMUserName') If $User='' Shell 'regedit /s "\\MAIN-SERVER\Support\Goldmine\GISMO\GISMO_@userid.reg"' ?"GISMO Installed for " + @userid Else ?"GISMO Already Installed for " + @userid EndIf EndIf
Basically, where I have GISMO_@userid.reg I have a file created, especially for this user based on their AD login name. I would need to create a unique .reg file for every user.
However, I was wondering if it is possible to enter this value based on some settings already within my AD? But, it's a little more complicated, I'm affraid... I will try to explain...
GoldMine only allows up to 8 charachters in the username. For various reasons, we decided to go with the format of First Name + first letter of Surname. e.g. JOEB for Joe Bloggs or PAULS for Paul Smith etc.
So, instead, I could import a standard .reg file and then follow that with a command that will edit the username registry entry based on the @fullname within Active Directory.
Something along the lines of...
IF @WKSTA="TS-SERVER" $User=ReadValue('HKEY_CURRENT_USER\Software\GoldMine\GoldMine Link for Microsoft Outlook','GMUserName') If $User='NONUSER' Shell 'regedit /s "\\MAIN-SERVER\Support\Goldmine\GISMO\GISMO.reg"' WriteValue("HKEY_CURRENT_USER\Software\GoldMine\GoldMine Link for Microsoft Outlook","GMUserName","@fullname","REG_SZ") ?" GISMO Installed for " + @userid Else ?" GISMO Already Installed for " + @userid EndIf EndIf
This works fine but enters the users Full Name and not the First Name + first letter of Surname
Any ideas on how I can acheive this?
Perhaps I could reference a single file with various entries for each user but this would still require me to make a file up.
|
Top
|
|
|
|
#172842 - 2007-01-16 07:23 PM
Re: Enter registry key, based on info from AD - but with a twist?
[Re: jon]
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
see Left() and split()
$name=@fullname
if instr($name,' ')
$left = left(split($name,' ')[0],7)
$right= left(split($name,' ')[1],1)
$shortname = $left+$right
endif
? $shortname
beware users with middle initials
of course if you are using Active directory, you can do this:
$ldap = TranslateName(1, @domain, 3, @ldomain+'\'+@userid, 1)
$UserProperties = GetObject("LDAP://"+$LDAP[0])
$FirstName = $userProperties.FirstName
$LastName = $userProperties.LastName
$left = left($FirstName,7)
$right= left($LastName,1)
$shortname = $left+$right
? $shortname
and include the translatename UDF
Edited by Radimus (2007-01-16 07:27 PM)
|
Top
|
|
|
|
#172867 - 2007-01-17 03:24 AM
Re: Enter registry key, based on info from AD - but with a twist?
[Re: NTDOC]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Rad's code a bit revised.
'User Name is: ' + Join(Split(GetUserADName(7,1),CHR(32)),'') ?
Function GetUserADName($FN,$LN)
Dim $LDAP, $UserProperties, $FirstName, $LastName
Dim $Left, $Right, $ShortName, $Err
$LDAP = TranslateName(1, @DOMAIN, 3, @LDOMAIN+'\'+@USERID, 1)
$Err = @ERROR
If $Err Exit $Err EndIf
$UserProperties = GetObject("LDAP://"+$LDAP[0])
$Err = @ERROR
If $Err Exit $Err EndIf
$FirstName = $UserProperties.FirstName
$LastName = $UserProperties.LastName
$Left = Trim(Left($FirstName,$FN)) ;$FN is the number of characters to get
$Right = Trim(Left($LastName,$LN)) ;$LN is the number of characters to get
$ShortName = $Left+CHR(32)+$Right
$GetUserADName = $ShortName
Exit @ERROR
EndFunction
Function TranslateName ($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
.
|
Top
|
|
|
|
#172896 - 2007-01-17 08:55 PM
Re: Enter registry key, based on info from AD - but with a twist?
[Re: NTDOC]
|
jon
Fresh Scripter
Registered: 2007-01-15
Posts: 11
|
Thanks for the code NTDOC. I will also make sure I enter my code properly.
I do still have a slight issue where some users first name is the same and the first letter of their surname clash. This causes their GoldMine user name to be slightly different.
The code would work most of the time but not all the time.
I have access to a file where all this information is stored in .dbf format. There are two specific fields within the .dbf file called 'USERNAME' and 'NAME'. The name is in the same format as Active Directory full name so the kixtart command @FULLNAME could be used to reference that line, to then get the GoldMine 'USERNAME' for that specific user.
So my question is, can kixtart reference information from files? More specifically a .dbf file? If not, I could export the info to .csv format if that's supported.
I have attached a sample dbf file for reference. I've added .ini to the end to allow upload.
If I can't reference lines within external files, I will use the code you provided and just have to fudge it for the odd user where it clashes.
Thanks again for any help.
Attachments
15-Users.DBF.ini (393 downloads) Description:
|
Top
|
|
|
|
#172897 - 2007-01-17 09:00 PM
Re: Enter registry key, based on info from AD - but with a twist?
[Re: jon]
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
see, that is why it should all be changed to be @userid.
yes it can read external files, but the DB commands are ... cumbersome.
However, reading an INI file is quite easy.
|
Top
|
|
|
|
#172931 - 2007-01-18 10:34 AM
Re: Enter registry key, based on info from AD - but with a twist?
[Re: NTDOC]
|
jon
Fresh Scripter
Registered: 2007-01-15
Posts: 11
|
Unfortunatly, GoldMine will only allow 8 characters in the username field. Otherwise, I would have used the same userid as AD and I wouldn't have any of these issues.
However, this .dbf file has the GM Username and is on the same line as the users Full Name which is co-incidentally the same as the AD Full Name. I was going to use this to match the two.
If I were to use an .ini file (which I could create based on the .dbf file), how would the file need to be layed out so I could search part of the file for @FULLNAME and then take the GM_USERID out to then enter into the registry?
|
Top
|
|
|
|
#172932 - 2007-01-18 10:44 AM
Re: Enter registry key, based on info from AD - but with a twist?
[Re: jon]
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
[names] @userid=goldmineid
$id = readprofilestring('Filename','names',@userid) if not @error or not $id ="" $nul= WriteValue("HKCU\Software\GoldMine\GoldMine Link for Microsoft Outlook","GMUserName",$id,REG_SZ) else ? "error finding name" endif
|
Top
|
|
|
|
#172957 - 2007-01-18 08:05 PM
Re: Enter registry key, based on info from AD - but with a twist?
[Re: Les]
|
jon
Fresh Scripter
Registered: 2007-01-15
Posts: 11
|
Les, that's a good idea on the 8.3 format but unfortunatly it wouldn't work too well for our specific user configuration. The user id's are in the format of SURNAME.F where F is the first letter of the forename. For example BLOGGS.J or BRAGG.J.
Therefore, where you get users with an 8 character surename, it also has a .X after which equates to 10 characters and therfore too long for GoldMine!
I hate GoldMine with a passion!!!!
I'll have a go with the ini file or do you still think it won't work too well?
|
Top
|
|
|
|
#172964 - 2007-01-18 11:01 PM
Re: Enter registry key, based on info from AD - but with a twist?
[Re: jon]
|
jon
Fresh Scripter
Registered: 2007-01-15
Posts: 11
|
Hi,
I've finally got the code I need and after lots of testing this seems to work perfectly.
Thanks to Radimus for pointing me in the right direction and to everyone else who helped.
If your interested, my final code is below.
IF @WKSTA="TS-SERVER"
$User1=ReadValue('HKEY_CURRENT_USER\Software\GoldMine\GoldMine Link for Microsoft Outlook','GMUserName')
If $User1=''
Shell 'regedit /s "\\MAIN-SERVER\Support\Goldmine\GISMO\GISMO.reg"'
$id=readprofilestring('\\MAIN-SERVER\Support\Goldmine\GISMO\GISMO.ini','names','@FULLNAME')
if $id =""
?" GISMO Not Configured!!"
?" Cant find GM User ID for " + @LDOMAIN "\" + @FULLNAME
?" Current GM User ID: " + $User1
else
WriteValue("HKCU\Software\GoldMine\GoldMine Link for Microsoft Outlook","GMUserName","$id","REG_SZ")
$User2=ReadValue('HKEY_CURRENT_USER\Software\GoldMine\GoldMine Link for Microsoft Outlook','GMUserName')
?" GISMO Configured for " + @LDOMAIN "\" + @FULLNAME " - Current GM User ID: " + $User2
endif
else
?" GISMO Configuration Not Changed! - Current GM User ID: " + $User1
EndIf
Once I've double checked that the AD FullName matches all the GoldMine FullNames, I will eventually rem out the If $USER='' entry and quite possibly the IF @WKSTA="TS-SERVER" so all PC's on my network are automatically setup.
This does mean I have to keep an .ini file up to date but that's reasonably easy to create from the .dbf file.
This is working but if anyone has any other ideas or better code, please let me know.
Thanks again, Jon.
|
Top
|
|
|
|
#172965 - 2007-01-18 11:06 PM
Re: Enter registry key, based on info from AD - but with a twist?
[Re: jon]
|
jon
Fresh Scripter
Registered: 2007-01-15
Posts: 11
|
Oh, by the way, the .ini file went like this...
[names] Joe Bloggs=JBLOGGS Joe Bragg=JBRAGG Paul Stewart=PAULS Frank Maynard=FRANKM
|
Top
|
|
|
|
#172966 - 2007-01-18 11:27 PM
Re: Enter registry key, based on info from AD - but with a twist?
[Re: jon]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Here is some feedback to improve it some. Not tested, just ideas.
Dim $User1, $ID, $RC, $User2
If @WKSTA="TS-SERVER"
$User1 = ReadValue('HKCU\Software\GoldMine\GoldMine Link for Microsoft Outlook','GMUserName')
If Not $User1
Shell 'regedit /s "\\MAIN-SERVER\Support\Goldmine\GISMO\GISMO.reg"'
$ID = ReadProfileString('\\MAIN-SERVER\Support\Goldmine\GISMO\GISMO.ini','names',@FULLNAME)
If Not $ID
" GISMO Not Configured!!" ?
" Cant find GM User ID for " + @LDOMAIN + "\" + @FULLNAME ?
; The line below should never display $User1 as it should only get here if it is blank
" Current GM User ID: " + $User1
Else
; The $RC line will be wrong as it should also only get here if $ID is blank so you would write a blank
; Which in turn would actually delete the value if one is there
$RC = WriteValue('HKCU\Software\GoldMine\GoldMine Link for Microsoft Outlook','GMUserName',$ID,REG_SZ)
$User2 = ReadValue('HKCU\Software\GoldMine\GoldMine Link for Microsoft Outlook','GMUserName')
" GISMO Configured for " + @LDOMAIN + "\" + @FULLNAME + " - Current GM User ID: " + $User2 ?
EndIf
Else
; This line shold always be blank for $User1 as you've not read it from the Registry yet
; And it only got here because the name of the system was not "TS-SERVER"
" GISMO Configuration Not Changed! - Current GM User ID: " + $User1 ?
EndIf
.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 569 anonymous users online.
|
|
|