Hi
I've been asked to write a script that will allow non admin users to
1) Reset a Given Users Password
2) Unlock a Given Users Accounts
i've written a partial script that checks to see if user is allowed (reads a file) and then will run the commands i'm working out how to do SU for the net user command (not that hard) but i can't get the ADSI part to work as an admin user...... i'd rather not use ADSI as most of the machines that will be running this program will be normal NT4 machines and i don't really want to install the DCclient on them
I've not figured out how to unlock an account yet but that will probably be easy using ADSI is there any other way?
here is the code so far
code:
; Key User script V1.0
; Created By PJF
;DEBUG ON
; Default Variables
$PASSWORD 123456
;MAIN SCRIPT
GOSUB AUTHORISEDUSER
CLS
? "Key User Script V1.0"
? "Please Select from the following options"
? " "
? "1 : Reset Users Password"
? "2 : Unlock USers Account"
? "3 : Exit"
? " "
? "Please Enter 1, 2 or 3: " GET $OPTION
SELECT
CASE $OPTION == "1" ; Reset Users Password
GOSUB RESETPASSWORD
EXIT
CASE $OPTION == "2" ; Unlock USers Account
GOSUB UNLOCKACCOUNT
EXIT
CASE $OPTION == "3" ; Exit
? "Press any Key to Exit" get $EXIT
EXIT
CASE 1 ; default option
? "Please try again and select either 1, 2 or 3"
EXIT
ENDSELECT
:AUTHORISEDUSER
CLS
$file = "auth.txt" ;file with usernames
If Open(1,"$file",2) <> 0
? '"@serror" opening $file'
? " "
? "You must provide a list of existing users for this script to work."
? "Call the file auth.txt"
? " "
Exit
EndIF
$NUL = Open(1,$file,2) ;this opens $file
$KEYUSER = ReadLine(1) ;this read's in the first line of $FILE.
AT(9,30) "Authorising User....."
BOX(10,10,12,65,"single")
$COL = 12
WHILE $COL < 64
AT(11,$COL) CHR(166)
$COL = $COL + 1
$Y = 100 * ($COL - 12) / 52
IF ($COL & RND() ) = 0 ; simulate activiity
SLEEP 1
ENDIF
LOOP
Do ;start loop
IF @USERID = $KEYUSER
$AUTHORISED = YES
ENDIF
$KEYUSER = ReadLine(1) ;this tells the script to get the next name in $FILE
Until @error <> 0 ;the do..until will run, grabbing each name in $FILE until the end is reached.
;End Loop when end of $FILE is reached
IF $AUTHORISED = "YES"
AT(15,0) "User is Authorised" get $EXIT
RETURN
ENDIF
AT(15,27) "USER IS NOT AUTHORISED"
AT(16,27) "Press any Key to Exit" get $EXIT
EXIT
RETURN
:RESETPASSWORD
? " "
? "Please enter username: " GETS $USERNAME
GOSUB BLANKPASSWORD
Shell '%comspec% /c net user "$USERNAME" "$PASSWORD" /domain >nul'
$A = GetObject("WinNT://sandh/$USERNAME,user")
$A.put("PasswordExpired", 1)
$A.setinfo
? "The Password for $USERNAME has been reset" GET $EXIT
RETURN
:UNLOCKACCOUNT
? " "
? "Please enter username: " GETS $USERNAME
:BLANKUSERNAME
IF $USERNAME = ""
? " "
? "USERNAME is Blank"
? " "
EXIT
ENDIF
RETURN
any help would be great, btw i'm sorry for the corney authorising user progress bar but i want the users to think something is actually happening......(so no flames please)
i also need to do some logging i.e. who runs the program and when and which users accounts they reset or unlock can anyone help with this?
Regards
Pete
[ 24 July 2002, 12:50: Message edited by: Peter Fry ]