Page 1 of 1 1
Topic Options
#59651 - 2001-10-06 04:14 PM Generate a Username
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands

I use a ASP site to ask the administrator the first name and last name of a new user. Now I like to generate a username with Kix Does someone know how to generate a username in a script?
Aditional: How do you check if a username allready exists?


#59652 - 2001-10-06 04:25 PM Re: Generate a Username
Les Offline
KiX Master

Registered: 2001-06-11
Posts: 12734
Check out this thread.
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

#59653 - 2001-10-06 09:40 PM Re: Generate a Username
pvds Offline

Registered: 2001-04-14
Posts: 201

We are managing some 1400 accounts and changing some 100 accounts a week. We use batch files to create modifi and delete users I think it could work with kix never tried it. we are using net user to create a user and CUsrMgr to modify the just created user CUsrMgr is in the recourse kit of win 2000 and it works fine in NT4. When there is time this week i am going to make a kix script with this an i wil post it here.

GR Peter

#59654 - 2001-10-07 10:47 AM Re: Generate a Username
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands

5 min after I asked this question i found thread.


I have send you a request for your code in NT shell scripting to your e-mail address.
I can use all the info there is.



#59655 - 2001-10-11 04:09 PM Re: Generate a Username
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands
It works.....

This is the final script.

-----------Beginning of script-----------break on
; Mkusr.kix
; Author: Frans Erich
; e-mail:
; Thanks to: Shawn Tassie's script at >
; What does this script do?
; 1. It generates a eight character NT username out of a tekst inputfile (Users.txt).
; 2. The generated name is checked for double entry's in the sam database and altered if it is double.
; 3. It will set the user enviorment like: Frist Password, Logon batch and Path to User- and profile directory.
; 4. Creates a user directory on the server.
; 5. Creates a profile directory on the server
; 6. Makes a hidden share the new user directory.
; 7. It removes the "Everyone" rights from the new user and profiles directories.
; 8. It assigns "Full Control" rights to The "administrator" and the new "username" over the new Profile- and user directory.
; The script is a part of a bigger sollution. The sollution works webanabled if you make a ASP website that makes the
; inputfile. You can make a costum service with SrvAny.exe from the resource that runs this script on your PDC.
; The service has to run onder the administrator account.
; In this case you have to make the script run in circles and give a time out with the "sleep" command in kix.
; Format of the value in the input file is:
; "John Dow" (without quotes)
; Files needed for this sript are:
; Kix32.exe from
; Addusers.exe from the NT Resource Kit
; Set Envirment Parameters
$domain = "yourdomain"
$password = "welcome"
$discription = "Domain User"
$homedrive = "H:"
$servername = "yourserver"
$userspath = users
$profilespath = "profiles$"
$batch = "logon.bat"
$inputfile = "C:\inetpub\wwwroot\mkusr\users.txt"
$outputfile = "C:\batch\mkusr\Mkusr.csv"
if open(1,"$inputfile") = 0
$username = readline(1)
; ----------- Set the initial amount of characters used. ----------
$fl = 1 ; for the first name characters
$ll = 7 ; for the last name characters
if $username
; ------------ Extract the surname from the complete name. -------------
$lastname = substr("$username",instr("$username"," ")+1,len("$username"))
; ------------ If it is to long then take only the first characters.-------------
if len ($lastname) >$ll
$lastname = substr("$lastname",1,$ll)
; ------------ Extract the christian name from the complete name. -----------
$firstname = substr("$username",1,instr("$username"," "))
; ------------ Generate the NT username.----------------
$userid = substr("$firstname",1,$fl) + $lastname
if len("$userid") > 1 ; id's should be at least 2 chars ...
; ------------ Check if the username already exist. -----------
SHELL '%comspec% /c NET USER $userid 2>null | FIND /c /i "Full name" >zero'
; ------------ If the username does not exits make it. ------------
if @error = 1
$nul = open(2,$outputfile,5)
$nul = writeline(2, "[users]," + chr(13) + chr(10))
$nul = writeline(2,"$userid,$username,$password,$discription,$homedrive,\\$servername\$userspath\$userid$,\\$servername\$profilespath\$userid,$batch")
$nul = close(2)
SHELL '%comspec% /c addusers \\$servername /c $outputfile'
; ------------ Make userdir and profiledir. ------------------
SHELL '%comspec% /c md \\$servername\$userspath\$userid'
SHELL '%comspec% /c md \\$servername\$profilespath\$userid'
; ------------ Make a hidden share from the userdir (option). ---------------
SHELL '%comspec% /c NET SHARE $userid$=D:\users\$userid /Y'
; ------------ Set rights on userdir and profiledir for only user and admingroup.----------
SHELL '%comspec% /c cacls \\$servername\$userspath\$userid /p administrator:f /t < C:\winnt\system32\Y.txt'
SHELL '%comspec% /c cacls \\$servername\$userspath\$userid /g $userid:f /e < C:\winnt\system32\Y.txt'
SHELL '%comspec% /c cacls \\$servername\$profilespath\$userid /p administrator:f /t < C:\winnt\system32\Y.txt'
SHELL '%comspec% /c cacls \\$servername\$profilespath\$userid /g $userid:f /e < C:\winnt\system32\Y.txt'
; ------------ If the username does exist use one more character of the first name.-----------
$fl = $fl + 1
; ------------ And one character less of the lastname. ----------------
$ll = $ll - 1
; ------------ And go back again to check that name. ---------------
goto again
; ------------ Close and clean up.----------------
$rs = close(1)
; del $inputfile
del $outputfile
del Null
del zero

--------------End of script-----------------

Good luck,


Page 1 of 1 1

Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
2 registered (Jochen, Allen) and 210 anonymous users online.
Newest Members
Romanc, Neurosine, Mads_H, Michael78, PaulBesafeglobal
17664 Registered Users

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

Search the board with:
superb Board Search
or try with google: