D
Dane
Does anyone know how to add Users to Groups using Visual Studio.net
2005? I am also trying to add them to the correct OU and finally I
would like to change the directory to where there terminal services
profiles are saved. THis is what I have thus far. Thanks!
Protected Sub btnNewUser_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnCreate.Click
Dim oContainer As ActiveDs.IADsContainer
Dim oUser As ActiveDs.IADsUser
Dim strFirstName As String
Dim strLastName As String
Dim strSAMAcctName As String
Dim oGroup As DictionaryEntry
strFirstName = Trim(Me.txtFirstName.Text)
strLastName = Trim(Me.txtLastName.Text)
strSAMAcctName = LCase(Left(strFirstName, 1) & strLastName)
oContainer = GetObject("LDAP://dc=HOMEHEALTH,dc=com")
oUser = oContainer.Create("user", "cn=" & strFirstName & " " &
strLastName)
oUser.Put("displayName", strFirstName & " " & strLastName)
oUser.Put("FirstName", strFirstName)
oUser.Put("LastName", strLastName)
oUser.Put("sAMAccountName", strSAMAcctName)
oUser.Put("userPrincipalName", strSAMAcctName &
"@HOMEHEALTH.COM")
oUser.EmailAddress = strSAMAcctName & "@americaneldercare.com"
oUser.homedrive = "U:"
oUser.HomeDirectory = "\\AEC1007\Users\" & strSAMAcctName
Try
oUser.SetInfo()
Catch
MsgBox("User Already Exists", MsgBoxStyle.Critical, "User
Exists!")
End Try
Try
If oUser.AccountDisabled = True Then
oUser.AccountDisabled = False
oUser.SetInfo()
End If
Catch ex As Exception
MsgBox("Error trying to enable account",
MsgBoxStyle.Critical, "Enable Account Failed")
Me.txtResults.Visible = True
End Try
Try
oUser.SetPassword(Me.txtPassword.Text)
oUser.Put("pwdLastSet", 0)
oUser.SetInfo()
Catch ex As Exception
MsgBox("Error trying to enable account",
MsgBoxStyle.Critical, "Enable Account Failed")
End Try
2005? I am also trying to add them to the correct OU and finally I
would like to change the directory to where there terminal services
profiles are saved. THis is what I have thus far. Thanks!
Protected Sub btnNewUser_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnCreate.Click
Dim oContainer As ActiveDs.IADsContainer
Dim oUser As ActiveDs.IADsUser
Dim strFirstName As String
Dim strLastName As String
Dim strSAMAcctName As String
Dim oGroup As DictionaryEntry
strFirstName = Trim(Me.txtFirstName.Text)
strLastName = Trim(Me.txtLastName.Text)
strSAMAcctName = LCase(Left(strFirstName, 1) & strLastName)
oContainer = GetObject("LDAP://dc=HOMEHEALTH,dc=com")
oUser = oContainer.Create("user", "cn=" & strFirstName & " " &
strLastName)
oUser.Put("displayName", strFirstName & " " & strLastName)
oUser.Put("FirstName", strFirstName)
oUser.Put("LastName", strLastName)
oUser.Put("sAMAccountName", strSAMAcctName)
oUser.Put("userPrincipalName", strSAMAcctName &
"@HOMEHEALTH.COM")
oUser.EmailAddress = strSAMAcctName & "@americaneldercare.com"
oUser.homedrive = "U:"
oUser.HomeDirectory = "\\AEC1007\Users\" & strSAMAcctName
Try
oUser.SetInfo()
Catch
MsgBox("User Already Exists", MsgBoxStyle.Critical, "User
Exists!")
End Try
Try
If oUser.AccountDisabled = True Then
oUser.AccountDisabled = False
oUser.SetInfo()
End If
Catch ex As Exception
MsgBox("Error trying to enable account",
MsgBoxStyle.Critical, "Enable Account Failed")
Me.txtResults.Visible = True
End Try
Try
oUser.SetPassword(Me.txtPassword.Text)
oUser.Put("pwdLastSet", 0)
oUser.SetInfo()
Catch ex As Exception
MsgBox("Error trying to enable account",
MsgBoxStyle.Critical, "Enable Account Failed")
End Try