Hello
I am trying to write a VBScript that extracts the account/userID from Active Directory and returns the useres real name. Through alot of searching and code experimenting I finally was able to get code to find and extract the users real name but when I get the user name in a variable I can't seem to do anything with it. For example I give the user an InputBox to enter a string I then attempt to cut the real name variable with the Split function into to single variables and the attempt to match the users input string with one of those variables. For some reason the split command will not work on the extracted Active Directory variable I pass to it. Is there something I am missing or should I be using a differnt command from split.
Here is my code.
Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim objProvNt
Dim strDomain, strOrg, strOrgType, strOrgLoc, strProvider
Dim strNameVar, strVar, strChar, strLine, testvar
Dim astrFullName()
Dim intStringLen, intIndex, intStart, intFlag
'strUserName = "(my user ID)"
strProvider = "WinNT://"
strDomain = "(my domain)"
strOrg = "(my organization)"
strOrgType = "net"
strOrgLoc = "(my organizations location)"
intFlag = 0
If intFlag = 0 Then
strNameVar = InputBox("Enter your name"
Set objProvNt = GetObject(strProvider & strDomain)
objProvNt.Filter = Array("User"
For Each strLine In objProvNt
On Error Resume Next
strVar = strLine.FullName
intStringLen = Len(strVar)
intStart = 1
For intIndex = 1 To intStringLen Step 1
strChar = Mid(strVar, intStart, 1)
If strChar = "," Then
strVar = LTrim(strVar)
strVar = RTrim(strVar)
astrFullName = Split(strVar, ","
' MsgBox "Variable before array split " & strVar
' MsgBox "Variable to search for " & strNameVar
MsgBox "First array element " & astrFullName(0)
MsgBox "Second array element " & astrFullName(1)
' If astrFullName(0) = strNameVar Then
' MsgBox "You found your person " & strVar
' ElseIf astrFullName(1) = strNameVar Then
' MsgBox "You foung your person " & strVar
' Else
' MsgBox "No one by that name was found"
' intFlag = 1
' End If
End If
intStart = intStart + 1
Next
Next
Else
MsgBox "All Done"
End If
I am trying to write a VBScript that extracts the account/userID from Active Directory and returns the useres real name. Through alot of searching and code experimenting I finally was able to get code to find and extract the users real name but when I get the user name in a variable I can't seem to do anything with it. For example I give the user an InputBox to enter a string I then attempt to cut the real name variable with the Split function into to single variables and the attempt to match the users input string with one of those variables. For some reason the split command will not work on the extracted Active Directory variable I pass to it. Is there something I am missing or should I be using a differnt command from split.
Here is my code.
Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim objProvNt
Dim strDomain, strOrg, strOrgType, strOrgLoc, strProvider
Dim strNameVar, strVar, strChar, strLine, testvar
Dim astrFullName()
Dim intStringLen, intIndex, intStart, intFlag
'strUserName = "(my user ID)"
strProvider = "WinNT://"
strDomain = "(my domain)"
strOrg = "(my organization)"
strOrgType = "net"
strOrgLoc = "(my organizations location)"
intFlag = 0
If intFlag = 0 Then
strNameVar = InputBox("Enter your name"
Set objProvNt = GetObject(strProvider & strDomain)
objProvNt.Filter = Array("User"
For Each strLine In objProvNt
On Error Resume Next
strVar = strLine.FullName
intStringLen = Len(strVar)
intStart = 1
For intIndex = 1 To intStringLen Step 1
strChar = Mid(strVar, intStart, 1)
If strChar = "," Then
strVar = LTrim(strVar)
strVar = RTrim(strVar)
astrFullName = Split(strVar, ","
' MsgBox "Variable before array split " & strVar
' MsgBox "Variable to search for " & strNameVar
MsgBox "First array element " & astrFullName(0)
MsgBox "Second array element " & astrFullName(1)
' If astrFullName(0) = strNameVar Then
' MsgBox "You found your person " & strVar
' ElseIf astrFullName(1) = strNameVar Then
' MsgBox "You foung your person " & strVar
' Else
' MsgBox "No one by that name was found"
' intFlag = 1
' End If
End If
intStart = intStart + 1
Next
Next
Else
MsgBox "All Done"
End If