Page 1 of 1 1
Topic Options
#17986 - 2002-02-26 05:57 PM How can I capture and trim the username?
Anonymous
Unregistered


I am going to be using ScriptLogic soon - a GUI based on the Kix32 language. We are currently using Firstname.Lastname as our username convention on our Win2000 domain. We are instituting a workstation naming convention that will include a department code + first initial + last name. Due to the convention, the last name will need to be truncated to 7 chars max.

Do you know how I could extract this information and store it as a variable? The department code is easy - it's standard. But how do I capture the first initial and the first 7 characters of the last name from the Firstname.Lastname username? Or can this be captured from another macro within Kixstart?

Top
#17987 - 2002-02-26 06:22 PM Re: How can I capture and trim the username?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jazzy,
If you're running AD, you should make ADSI your friend. It will get you what you need.
Don't know where you are on that scale so will suggest the you start with the M$ Active Directory SDK. Within it is adsi25.chm a help file that explains the IADsUser Property Methods. You can also search our forums for "IADsUser" for some examples.
In so far as the KiX macros, they will put out only what you put in the users' property. I can't imagine where you would use macros however, as they only return the user that is running the script. Will users be renaming their own computers?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#17988 - 2002-02-26 06:25 PM Re: How can I capture and trim the username?
Anonymous
Unregistered


Here's a start. This will get you the first 7 letters of the last name as long as you have their full name in User Manager for Domains.

$LNAME = SUBSTR(@FULLNAME,1,7)

Top
#17989 - 2002-02-26 06:40 PM Re: How can I capture and trim the username?
Anonymous
Unregistered


Thank you for the great suggestions, LLigetfa and MikeT. I will definitely have to check out ADSI via the adsi25.chm help file.
And MikeT, thanks for the tip in using SUBSTR. Possibly I could use this to grab only the first letter of the full name, right? Then I could put the 2 values together to form the firstinitial+lastname convention I want.
The purpose of this is to be able to automatically rename a few hundred 9x workstations instead of having to walk around personally. Of course, it will require a reboot to take effect, but that's not a problem.

Top
#17990 - 2002-02-26 07:18 PM Re: How can I capture and trim the username?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jazzy,
Being as nosey as I am, I will critique your methodology. Somehow the idea of renaming a computer based on who logs in doesn't sit well with me. Personally, I whould collect data on the PCs and users for a while. Then I would compile a table of name changes and lookup the names in the table for the change.

The table could be as simple as an INI file you could query with ReadProfileString() and contain OldName=NewName.

Just my $.02 (in Canadian dollars)

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#17991 - 2002-02-26 07:59 PM Re: How can I capture and trim the username?
Anonymous
Unregistered


It's gonna be a little tougher to get the first initial using the @FULLNAME and the SUBSTR command. What format do you use for your username (ex. First Initial, Last Name BSmith or Last Name First Initial SmithB).
Top
#17992 - 2002-02-26 08:33 PM Re: How can I capture and trim the username?
Will Hetrick Offline
Hey THIS is FUN

Registered: 2001-10-02
Posts: 320
Loc: Harrisburg, PA USA
Since your login names are currently firstname.lastname, Do a substr(@userid,1,1) to get the first letter of the first name.
then do a while loop that looks for the "." while substr(@userid,$count,1) <> "." loop then when you find the period, add one more to substring and take the next 7 characters.
substr(@userid,$count+1,7).

This was just brainstorming. The code should be easy enough.

_________________________
You have at least 2 choices. Each choice changes your destiny. Choose wisely!

Top
#17993 - 2002-02-26 08:37 PM Re: How can I capture and trim the username?
Anonymous
Unregistered


MikeT,
We are using Firstname.Lastname, ie Joe.Smith. Thanks!

Top
#17994 - 2002-02-26 08:50 PM Re: How can I capture and trim the username?
Anonymous
Unregistered


$FINIT = SUBSTR(@USERID,1,1)

Will give you the first initial and
$FINITLNAME = "$FINIT" + "$LNAME"

Will add them together.

Top
#17995 - 2002-02-26 09:15 PM Re: How can I capture and trim the username?
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
here

$newname = substr(@userid,1,1)+substr(@userid,instr(@userid,".")+1,len(@userid))


Bryce

Top
#17996 - 2002-02-26 10:00 PM Re: How can I capture and trim the username?
Anonymous
Unregistered


Bryce,
Thanks for your input!
I think I had it worked out with a while - do loop, but a single expression is even better.
Since I only want 7 letters of the last name, I think the following modification would work well. What do you think?

$newname = substr(@userid,1,1)+substr(@userid,instr(@userid,".")+1,7)

Top
#17997 - 2002-02-27 06:50 PM Re: How can I capture and trim the username?
Anonymous
Unregistered


Thanks again for all your input. I have implemented Bryce's solution and it is working great - very fast!
I have also implemented a message box to allow the user to cancel the registry change should the need arise. Thanks!

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 1013 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.054 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