Click here to Skip to main content
15,901,035 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: test Pin
NotPolitcallyCorrect9-Sep-16 7:47
NotPolitcallyCorrect9-Sep-16 7:47 
QuestionMicrosoft.VisualBasic.FileIO.TextFieldParser Pin
#realJSOP9-Sep-16 5:51
professional#realJSOP9-Sep-16 5:51 
AnswerRe: Microsoft.VisualBasic.FileIO.TextFieldParser Pin
Richard Deeming9-Sep-16 6:49
mveRichard Deeming9-Sep-16 6:49 
GeneralRe: Microsoft.VisualBasic.FileIO.TextFieldParser Pin
#realJSOP9-Sep-16 7:28
professional#realJSOP9-Sep-16 7:28 
AnswerRe: Microsoft.VisualBasic.FileIO.TextFieldParser Pin
Richard MacCutchan9-Sep-16 21:40
mveRichard MacCutchan9-Sep-16 21:40 
QuestionAssembly. Pin
Member 111616259-Sep-16 2:00
Member 111616259-Sep-16 2:00 
AnswerRe: Assembly. Pin
Pete O'Hanlon9-Sep-16 2:17
mvePete O'Hanlon9-Sep-16 2:17 
QuestionActive Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA7-Sep-16 20:29
professionalJANAZA7-Sep-16 20:29 
Hi Guys, hope my question is formed well enough and thanks for everyone who contributes to this site as I have had many successes in projects through Codeproject. However it is my first time asking a question. I have been struggling now for a good couple of days with the above. I am reading to AD and writing but for the life of me i just seem not to be able to write to the above. Following is my code: If any one can please assist me or point me into the right direction...please...and thank you really a lot.

C#
    Dim RootDSE As String
    Dim DSESearcher As DirectorySearcher = New System.DirectoryServices.DirectorySearcher
    Try
        RootDSE = DSESearcher.SearchRoot.Path
        RootDSE = RootDSE.Insert(7, Utility.ADUsersPath & ",")
        Dim myDE As DirectoryEntry = New DirectoryEntry(RootDSE)
        Dim myEntries As DirectoryEntries = myDE.Children
        Dim myDirectoryEntry As DirectoryEntry = myEntries.Add("CN=" + DisplayName, "user")
        Utility.SetProperty(myDirectoryEntry, "givenName", FirstName)
        Utility.SetProperty(myDirectoryEntry, "initials", MiddleInitial)
        Utility.SetProperty(myDirectoryEntry, "sn", LastName)
        Utility.SetProperty(myDirectoryEntry, "displayName", DisplayName)
        If UserPrincipalName <> "" Then
            Utility.SetProperty(myDirectoryEntry, "UserPrincipalName", UserPrincipalName)
        Else
            Utility.SetProperty(myDirectoryEntry, "UserPrincipalName", UserName)
        End If
        Utility.SetProperty(myDirectoryEntry, "PostalAddress", PostalAddress)
        Utility.SetProperty(myDirectoryEntry, "StreetAddress", MailingAddress)
        Utility.SetProperty(myDirectoryEntry, "HomePostalAddress", ResidentialAddress)
        Utility.SetProperty(myDirectoryEntry, "Title", Title)
        Utility.SetProperty(myDirectoryEntry, "HomePhone", HomePhone)
        Utility.SetProperty(myDirectoryEntry, "TelephoneNumber", OfficePhone)
        Utility.SetProperty(myDirectoryEntry, "Mobile", Mobile)
        Utility.SetProperty(myDirectoryEntry, "FacsimileTelephoneNumber", Fax)
        Utility.SetProperty(myDirectoryEntry, "mail", Email)
        Utility.SetProperty(myDirectoryEntry, "Url", Url)
        Utility.SetProperty(myDirectoryEntry, "sAMAccountName", UserName)
        Utility.SetProperty(myDirectoryEntry, "UserPassword", Password)
        Utility.SetProperty(myDirectoryEntry, "description", Description)
        'Utility.SetProperty(myDirectoryEntry, "homeDrive", HomeDrive)
        'Utility.SetProperty(myDirectoryEntry, "homeDirecrtory", HomeDirectory)
        Utility.SetProperty(myDirectoryEntry, "scriptPath", ScriptPath)
        myDirectoryEntry.Properties("userAccountControl").Value = Utility.UserStatus.Enable
        ''1ST COMMIT VALIDATES AGAINST USERNAME AND DISPLAY NAME RESPECTIVELY
        myDirectoryEntry.CommitChanges()

        SetMember(DisplayName, MemberOF)
        ''USE DISPLAY: USERNAME FAIL WHEN CREATING PASSWORD
        myDirectoryEntry = GetUser(DisplayName)
        Utility.SetUserPassword(myDirectoryEntry, Password)
        myDirectoryEntry.Properties("userAccountControl").Value = Utility.ADAccountOptions.UF_DONT_EXPIRE_PASSWD
        myDirectoryEntry.CommitChanges()
        myDirectoryEntry.Properties("userAccountControl").Value = Utility.ADAccountOptions.UF_PASSWD_CANT_CHANGE
        myDirectoryEntry.CommitChanges()
        Return myDirectoryEntry
    Catch ex As Exception
        If Not ex.InnerException Is Nothing Then
            MsgBox(ex.InnerException.Message)
        End If
        'Throw New Exception(ex.Message)
        MsgBox(ex.Message)
        Throw ex
    End Try
End Function

Private Function SetMember(ByVal DisplayName As String, ByVal memberOF As String) As Integer
    Dim RootDSE As String
    Dim DSESearcher As DirectorySearcher = New System.DirectoryServices.DirectorySearcher
    RootDSE = DSESearcher.SearchRoot.Path
    RootDSE = RootDSE.Insert(7, Utility.ADUsersPath & ",")

    Dim myDE As DirectoryEntry = New DirectoryEntry(RootDSE)
    Dim myEntries As DirectoryEntries = myDE.Children

    Try
        'For Each thisGroup As [String] In memberOF
        Dim myParent As DirectoryEntries = myDE.Parent.Children
        Dim newGroup As DirectoryEntry = myParent.Find("CN=" + memberOF, "group")

        If newGroup IsNot Nothing Then
            Dim myDirectoryEntry As DirectoryEntry = myEntries.Add("CN=" + DisplayName, "user")
            newGroup.Invoke("Add", New Object() {myDirectoryEntry.Path.ToString()})
            myDirectoryEntry.CommitChanges()
            newGroup.Close()
        End If
        'Next
    Catch ex As Exception
        If Not ex.InnerException Is Nothing Then
            MsgBox(ex.InnerException.Message)
        End If
        'Throw New Exception(ex.Message)
        MsgBox(ex.Message)
    End Try

End Function


Again, thank you for any input
AnswerRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
Dave Kreskowiak8-Sep-16 6:25
mveDave Kreskowiak8-Sep-16 6:25 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA8-Sep-16 9:31
professionalJANAZA8-Sep-16 9:31 
AnswerRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
Richard Deeming8-Sep-16 10:24
mveRichard Deeming8-Sep-16 10:24 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA9-Sep-16 1:30
professionalJANAZA9-Sep-16 1:30 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA9-Sep-16 2:56
professionalJANAZA9-Sep-16 2:56 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
Richard Deeming9-Sep-16 3:02
mveRichard Deeming9-Sep-16 3:02 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA9-Sep-16 3:17
professionalJANAZA9-Sep-16 3:17 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
Richard Deeming9-Sep-16 3:23
mveRichard Deeming9-Sep-16 3:23 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA9-Sep-16 3:45
professionalJANAZA9-Sep-16 3:45 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
Richard Deeming9-Sep-16 4:11
mveRichard Deeming9-Sep-16 4:11 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA9-Sep-16 4:27
professionalJANAZA9-Sep-16 4:27 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
Richard Deeming9-Sep-16 4:35
mveRichard Deeming9-Sep-16 4:35 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA9-Sep-16 8:08
professionalJANAZA9-Sep-16 8:08 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA11-Sep-16 19:52
professionalJANAZA11-Sep-16 19:52 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA11-Sep-16 22:37
professionalJANAZA11-Sep-16 22:37 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
Richard Deeming12-Sep-16 1:55
mveRichard Deeming12-Sep-16 1:55 
GeneralRe: Active Directory : User account options, Homefolder drive and directory and memberof group Pin
JANAZA12-Sep-16 2:23
professionalJANAZA12-Sep-16 2:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.