S
styx31
I'm trying to create users through ADSI using VB.NET. Using
DirectoryServices. I'm using WINNT://ComputerName
I've found examples to create user and modify their properties, by using
the method InvokeProperty ie. in c#.
But this function doesn't exist in VB.NET, and I was unable to find a
synonym. So, I've tried using other methods, but with no success...
Here is my code :
-------------------------------
' Consider Username is correctly filled with a valid system username
Dim usr As System.DirectoryServices.DirectoryEntry
' Get the user
usr = _DSHelper.ADFind(Username, "user")
' Exploring Properties for debug purposes
' In the properties returned, I can read all and view
' that they meet the account edited
Dim penum As System.Collections.IDictionaryEnumerator =
usr.Properties.GetEnumerator()
While penum.MoveNext()
Console.Write(CStr(penum.Key) & "=")
Dim penumvalue As System.Collections.IEnumerator = CType(penum.Value,
PropertyValueCollection).GetEnumerator()
While (penumvalue.MoveNext())
Console.Write(penumvalue.Current.ToString())
End While
Console.WriteLine("")
End While
' Verify loading of the user
Console.WriteLine(usr.Properties("FullName").Value) ' Returns 'toto'
' Change the Fullname property
' Returns an Undefined COM Exception
usr.Properties("FullName").Value = "titi"
' Not better...
usr.Invoke("put_FullName", New Object() {"titi"})
DirectoryServices. I'm using WINNT://ComputerName
I've found examples to create user and modify their properties, by using
the method InvokeProperty ie. in c#.
But this function doesn't exist in VB.NET, and I was unable to find a
synonym. So, I've tried using other methods, but with no success...
Here is my code :
-------------------------------
' Consider Username is correctly filled with a valid system username
Dim usr As System.DirectoryServices.DirectoryEntry
' Get the user
usr = _DSHelper.ADFind(Username, "user")
' Exploring Properties for debug purposes
' In the properties returned, I can read all and view
' that they meet the account edited
Dim penum As System.Collections.IDictionaryEnumerator =
usr.Properties.GetEnumerator()
While penum.MoveNext()
Console.Write(CStr(penum.Key) & "=")
Dim penumvalue As System.Collections.IEnumerator = CType(penum.Value,
PropertyValueCollection).GetEnumerator()
While (penumvalue.MoveNext())
Console.Write(penumvalue.Current.ToString())
End While
Console.WriteLine("")
End While
' Verify loading of the user
Console.WriteLine(usr.Properties("FullName").Value) ' Returns 'toto'
' Change the Fullname property
' Returns an Undefined COM Exception
usr.Properties("FullName").Value = "titi"
' Not better...
usr.Invoke("put_FullName", New Object() {"titi"})