Hi,
I have a list of usernames in a text file that are validated against AD. I have a msgbox that triggers when a username doesn't match. The msgbox has Abort / Retry / Ignore buttons.
If a mismatch between the username in the text file and AD ocures, I'd like to give the user the option to correct the username within the file, save the file and re-run the code if the user clicks Retry.
I am having difficulty getting the function that reads the text file to 'notice' the change to the file. I've tried various ways but still haven't managed it. Currently, it ignores the changes and returns the correct usernames.
Below is the function call and the function itself that reads the text file:
If anyone could point me in the right direction on how to get the function to re-check the file, I'd be most grateful
Many thanks
T
I have a list of usernames in a text file that are validated against AD. I have a msgbox that triggers when a username doesn't match. The msgbox has Abort / Retry / Ignore buttons.
If a mismatch between the username in the text file and AD ocures, I'd like to give the user the option to correct the username within the file, save the file and re-run the code if the user clicks Retry.
I am having difficulty getting the function that reads the text file to 'notice' the change to the file. I've tried various ways but still haven't managed it. Currently, it ignores the changes and returns the correct usernames.
Below is the function call and the function itself that reads the text file:
Code:
For Each u In getUserList(strUsername)
WScript.Echo i
Next
Function getUserList(strUsername)
Dim vRerun, vProblem
vRerun = False
vProblem = False
Set oDict = CreateObject("Scripting.Dictionary")
If InStr(1,strUsername, ":\") Then
If fso.FileExists(strUsername) Then
Set oTextFile = fso.OpenTextFile(strUsername, 1)
i = 0
Do Until oTextFile.AtEndOfStream
strNextLine = oTextFile.Readline
i=i+1
If validateUsername(strNextLine) Then
'only add valid usernames.
oDict.Add i,strNextLine
Else
vProblem = True
intOut = MsgBox("A user with the name " & Chr(34) & strNextLine & Chr(34) & " cannot be found in AD." & VbCrLf & _
"Please correct the username in the file " & strUsername & ", save the file and click Retry.",18,"Error!")
If intOut = 3 Then 'Abort
MsgBox "You have aborted this script!",16,"Abort"
'validateUsername = False
WScript.Quit
ElseIf intOut = 4 Then 'Retry
'MsgBox "Out: " & intOut
oTextFile.close
Set oTextFile = fso.OpenTextFile(strUsername, 1)
'vRerun = True
'Exit Do
End If
End If
Loop
oTextFile.Close
If vRerun = True Then
getUserList(strUsername)
End If
End If
Else
MsgBox "Cannot find specified file.",16,"Missing File."
End If
'If vProblem = False Then
getUserList = oDict.Items
'End If
End Function
If anyone could point me in the right direction on how to get the function to re-check the file, I'd be most grateful
Many thanks
T