Script for auto changing control assessment passwords
Barely anyone outside these circles can understand the frustration one has from windows when
Spent 5 hours writing the perfect script for changing the control assessment passwords.
It
chooses a random word out of 1600
changes the passwords using dsmod
writes them to files on the staff drive
emails them to relevant teachers using blat.
It took 5 hours because I don't code in vbscript often so practically every line had errors. Only 34 lines... Also originally I was going to have the vbs get the word and then feed it into a batch file to do the rest but later i realised I could do the whole lot in vbs using object.run.
2 hours later, today.....I can not make it work in a scheduled task and it doesn't tell me why it doesn't work.
I've tried using cscript in the scheduled task and a batch file that works from the command line.
Update
I found out how to get a log file from a scheduled batch file from here: Functional Fun: Debugging Windows batch files when used as scheduled tasks
Turns the out the problem all along that I hadn't noticed is where it initialises the text files it refers to them by drive letter which doesn't exist in the environment the scheduled task runs in.
Here is the script:
Const ForReading = 1, ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("wordlist.csv", ForReading)
thefile=objtextfile.readall
myArray = Split(theFile,vbcrlf)
objtextfile.close
function getword()
Dim max,min
max=1162
min=1
Randomize
getnumber=Int((max-min+1)*Rnd+min)
getword=myarray(getnumber)
wscript.echo(getword)
end function
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
Set f = objFSO.OpenTextFile("\\server\staffdrive\controlassessi.txt", ForWriting, True)
Set g = objFSO.OpenTextFile("\\server\staffdrive\controlassess.txt", ForWriting, True)
'controlassessi password change
tempword=getword()
f.writeline(tempword)
objShell.Run ("c:\windows\system32\dsmod.exe user " & Chr(34) & "cn=controlled assessmenti,ou=pupils,dc=domain" & Chr(34) & " -pwd " & tempword), false
objShell.Run ("blat - -body " & chr(34) & "new controlassessi password is " & tempword & chr(34) & " -to browolf@domain -server server -f academic\administrator -subject " & chr(34) & "new controlassessi password" & chr(34)),false
'controlassess no internet password change
tempword=getword()
g.writeline(tempword)
objShell.Run ("c:\windows\system32\dsmod user " & Chr(34) & "cn=controlled assessments,ou=internetban,ou=pupils,dc=domain" & Chr(34) & " -pwd " & tempword),false
objShell.run ("blat - -body " & chr(34) & "new controlassess password is " & tempword & chr(34) & " -to browolf@domain -server server -f academic\administrator -subject " & chr(34) & "new controlassess password" & chr(34)), false
f.close
g.close
Edited by browolf

1 Comment
Recommended Comments
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now