Page 1 of 2 12>
Topic Options
#25794 - 2002-07-25 12:29 AM help required on this script
Peter Fry Offline
Getting the hang of it

Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
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 ]

Top
#25795 - 2002-07-24 03:00 PM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
*bumb*

peter, seems that your post is getting missed on this forum...
just making a bumb not actually answering as I haven't done even one script using adsi.

better luck can be achieved with this type of script in related forum as they have less posts and experts looking more deeply...

just to give you another way on that locked thing, how about:
net user $username /active:yes /domain

cheers.
_________________________
!

download KiXnet

Top
#25796 - 2002-07-24 03:06 PM Re: help required on this script
Peter Fry Offline
Getting the hang of it

Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
well i'm now making all the key users members of the account operator groups so i can get rid of the permissions problem [Smile] (sneaky eh?)

i posted here because i didn't want a ADSI solution....... i just can't see anyother way of doing it atm

i can use net user to set a password i just can't get a command util that comes with NT to set the password expires flag - any ideas?

does net user $username /active:yes /domain clear the unlocked or just clear the deactived? flag?

i'm asking this because currently we are not using any password controls so i can't get the account lock out flag to be set to test........

if i can use net user i'd be very happy

my ideal solution is that i can use net user etc for evertyhing and not adsi so i don't have to install DCclients on my NT4 machines

thanks for the bump [Smile]

Regards

Pete

Top
#25797 - 2002-07-24 03:17 PM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I tested and the /active:yes removes the lockdown-flag

cheers,
_________________________
!

download KiXnet

Top
#25798 - 2002-07-24 03:18 PM Re: help required on this script
Peter Fry Offline
Getting the hang of it

Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
you STAR [Smile] thanks alot this saves me lots of time [Smile]
Top
#25799 - 2002-07-24 03:24 PM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
isn't that expiration global policy setting?
so if you have as global setting in user manager that the change should happen every 90 days, the password will automatically be required to change in 90 days after last change.
_________________________
!

download KiXnet

Top
#25800 - 2002-07-24 03:35 PM Re: help required on this script
Peter Fry Offline
Getting the hang of it

Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
yes but if you use

Shell '%comspec% /c net user "$USERNAME" "$PASSWORD" /domain >nul'

it sets the password but doesn't set the expiredflag so it doesn't ask the user to change it on next logon

Top
#25801 - 2002-07-24 03:43 PM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I made an exe some 2 years ago for putting on the "user must change password on next logon"-flag.
as it's not doable with the net user.
and at that time didn't find anyway to do it.
so coded it myself with some netusersetinfo 11 or 13 structure...

shawn might be able to say how it's easier and I might find that exe lying in somewhere...
_________________________
!

download KiXnet

Top
#25802 - 2002-07-24 03:47 PM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, found it.
it has even my old info...
if there is need for (don't think there is after this adsi and wmi stuff) could even update it.

download and try.
it's in www.gwspikval.com/jooel/scripts

mustikka is the name.
_________________________
!

download KiXnet

Top
#25803 - 2002-07-24 04:01 PM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
btw, it was coded as part of usermodificator script did at that time and it was put on the server and connected with rcmd.
it queries only the local machines users and as such to get it work on domain accounts it needs to be placed on dc...

cheers,
_________________________
!

download KiXnet

Top
#25804 - 2002-07-24 04:15 PM Re: help required on this script
Peter Fry Offline
Getting the hang of it

Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
Lonkero

it looks like a great program - one thing i need to be able to run it from workstations and not DCs
the program recommends it is ran on DC and i can't seem to get your program to work when ran on my local machine.

i just can't believe there is nothing in standard in NT to set this flag [Frown]

keep the help flowing tho it's all good

Top
#25805 - 2002-07-24 06:05 PM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
peter, sorry there is not.
that's why I did that.

I may look into this to get it work on wksta's too.

have the source code on my laptop so I will check.
_________________________
!

download KiXnet

Top
#25806 - 2002-07-24 07:14 PM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok...
found the way. now I just need to walk on it.
I probably get the code done today but can't test it before tomorrow.
_________________________
!

download KiXnet

Top
#25807 - 2002-07-24 09:28 PM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
now also code is running...
little bit more brains to catch the commandline addings and it's done.

you know, what more often you do these, that easier these codes get...
jippii...
_________________________
!

download KiXnet

Top
#25808 - 2002-07-25 09:09 AM Re: help required on this script
Peter Fry Offline
Getting the hang of it

Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
can i download it from the same place as before?

thanks for the help [Smile]

Top
#25809 - 2002-07-25 11:20 AM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes...
I'll let you know when I got it worky worky.
I'm still at home and going to work in an hour.
before that I have nothing to test on (no windows PDC's at my home [Big Grin] )

I have come up with multiple kix-related projects but this pushes over all of them for the next 5 hours...
_________________________
!

download KiXnet

Top
#25810 - 2002-07-25 04:53 PM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it seems that the communication between server and client is not possible...
it keeps giving me error 87 even though the servers eventlog says all was succesfull.
I have to keep looking, but can't put too much time to this...
_________________________
!

download KiXnet

Top
#25811 - 2002-07-26 11:41 AM Re: help required on this script
Peter Fry Offline
Getting the hang of it

Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
thanks for all your help Lonkero, if you don't have time it's ok i'll find some other way of achieving this, i might have to go the adsi route

thanks again

Pete

Top
#25812 - 2002-07-27 12:54 AM Re: help required on this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
peter, it's not anymore about time.
I can't get over this error and if I do what msdn states I get 10 errors more.
also it suggests some changes that are needed for xp clients and my box don't have those libraries...

I'll see more into this for sure. only think that changes is that I lower it's priority to get other things done too...

[ 26 July 2002, 13:15: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#25813 - 2002-07-26 01:31 PM Re: help required on this script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Beach,

careful with that one ;
sleep doesn't accept variables (tried it with different delay values below 1 )
It doesn't even execute()

J.
_________________________



Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.088 seconds in which 0.035 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