Grutte Pier
(Getting the hang of it)
2001-10-06 04:14 PM
Generate a Username

Hello,

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?

Thanks,
Frans

Les
(KiX Master)
2001-10-06 04:25 PM
Re: Generate a Username

Check out this thread.
http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=002295


pvds
(Hey THIS is FUN)
2001-10-06 09:40 PM
Re: Generate a Username

Hi,

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

Grutte Pier
(Getting the hang of it)
2001-10-07 10:47 AM
Re: Generate a Username

Thanks,

5 min after I asked this question i found thread. http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=002295

Peter,

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.

Thanks,

Frans

Grutte Pier
(Getting the hang of it)
2001-10-11 04:09 PM
Re: Generate a Username

It works.....

This is the final script.

-----------Beginning of script-----------break on
; Mkusr.kix
; Author: Frans Erich
; e-mail: f.erich@chello.nl
;
; Thanks to: Shawn Tassie's script at www.kixtart.org > http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=002295
;
; 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 www.kixtart.org
; 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
:Again
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)
endif
; ------------ 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'
Else
; ------------ 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
endif
endif
endif
; ------------ Close and clean up.----------------
$rs = close(1)
; del $inputfile
del $outputfile
del Null
del zero
exit

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

Good luck,

Frans