473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Using Directory Services saves some settings and not others

#Region "Imports

Imports ADSSECURITYLi
Imports System.Diagnostic
Imports Scriptin
Imports ActiveD
Imports System.DirectoryService
Imports System.Configuration.ConfigurationSetting
Imports System.I

#End Regio

Public Class Utilit
Inherits System.Web.UI.Pag

#Region "Constants

Const ADS_UF_SCRIPT = &H
Const ADS_UF_ACCOUNTDISABLE = &H
Const ADS_UF_HOMEDIR_REQUIRED = &H
Const ADS_UF_LOCKOUT = &H1
Const ADS_UF_PASSWD_NOTREQD = &H2
Const ADS_UF_PASSWD_CANT_CHANGE = &H4
Const ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = &H8
Const ADS_UF_TEMP_DUPLICATE_ACCOUNT = &H10
Const ADS_UF_NORMAL_ACCOUNT = &H20
Const ADS_UF_INTERDOMAIN_TRUST_ACCOUNT = &H80
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &H100
Const ADS_UF_SERVER_TRUST_ACCOUNT = &H200
Const ADS_UF_DONT_EXPIRE_PASSWD = &H1000
Const ADS_UF_MNS_LOGON_ACCOUNT = &H2000
Const ADS_UF_SMARTCARD_REQUIRED = &H4000
Const ADS_UF_TRUSTED_FOR_DELEGATION = &H8000
Const ADS_UF_NOT_DELEGATED = &H10000
Const ADS_UF_USE_DES_KEY_ONLY = &H20000
Const ADS_UF_DONT_REQUIRE_PREAUTH = &H40000
Const ADS_UF_PASSWORD_EXPIRED = &H80000
Const ADS_UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION = &H100000

#End Regio

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa

Dim AccountName as strin
Dim Password as Strin

AccountName = "SEA1010
Password = "123456789

AddAccount(AccountName, Password

End Su

Private Sub SetPassword(ByVal AccountName As String, ByVal Password As String

Dim MyDirectoryEntry As DirectoryEntr
Dim MyDirectorySearcher As DirectorySearche
Dim MyGroup As DirectoryEntr
Dim MyUser As DirectoryEntr
Dim MyUserAccountControl As Intege

MyDirectoryEntry = New DirectoryEntry("LDAP://" & AppSettings("LDAPPath"), AppSettings("Domain") & "\" & AppSettings("Administrator"), AppSettings("Password")
MyDirectorySearcher = New DirectorySearcher(MyDirectoryEntry
MyDirectorySearcher.Filter = "(samAccountName=" & AccountName & ")
MyUser = New DirectoryEntry(MyDirectorySearcher.FindOne.GetDire ctoryEntry.Path
MyUser.AuthenticationType = AuthenticationTypes.Secur
MyUser.Invoke("SetPassword", New Object() {Password}

MyUserAccountControl = MyUser.Properties("userAccountControl").Valu
MyUser.Properties("userAccountControl").Value = MyUserAccountControl Or ADS_UF_DONT_EXPIRE_PASSW
MyUser.Properties("userAccountControl").Value = MyUserAccountControl Or ADS_UF_PASSWD_CANT_CHANG

MyDirectoryEntry.CommitChanges(
MyDirectoryEntry.RefreshCache(

End Su

Private Sub CreateAccount(ByVal AccountName As String

Dim MyDirectoryEntry As DirectoryEntr
Dim MyDirectorySearcher As DirectorySearche
Dim MyGroup As DirectoryEntr
Dim MyUser As DirectoryEntr

MyDirectoryEntry = New DirectoryEntry("LDAP://" & AppSettings("LDAPPath"), AppSettings("Domain") & "\" & AppSettings("Administrator"), AppSettings("Password")
MyUser = MyDirectoryEntry.Children.Add("cn=" & AccountName & ",ou=" & AppSettings("LDAPOU"), "user"
MyUser.Properties("sn").Add(AccountName
MyUser.Properties("displayName").Add(AccountName
MyUser.Properties("samAccountName").Add(AccountNam e
MyUser.Properties("homeDirectory").Add(AppSettings ("FTPDirectoryPath") & AccountName
MyUser.Properties("accountExpires").Add(0

MyUser.CommitChanges(
MyUser.RefreshCache(

End Su

Private Sub SetGroup(ByVal AccountName As String

Dim MyDirectoryEntry As DirectoryEntr
Dim MyDirectorySearcher As DirectorySearche
Dim MyGroup As DirectoryEntr
Dim MyUser As DirectoryEntr

MyDirectoryEntry = New DirectoryEntry("LDAP://" & AppSettings("LDAPPath"), AppSettings("Domain") & "\" & AppSettings("Administrator"), AppSettings("Password")
MyDirectorySearcher = New DirectorySearcher(MyDirectoryEntry
MyDirectorySearcher.Filter = "(samAccountName=" & AccountName & ")"
MyUser = New DirectoryEntry(MyDirectorySearcher.FindOne.GetDire ctoryEntry.Path)

MyDirectoryEntry = New DirectoryEntry("LDAP://" & AppSettings("LDAPPath") & "/CN=" & AppSettings("LDAPCN") & ",OU=" & AppSettings("LDAPOU") & " , " & AppSettings("LDAPDCPath"), AppSettings("Domain") & "\" & AppSettings("Administrator"), AppSettings("Password"))
MyDirectoryEntry.Invoke("Add", New Object() {MyUser.Path.ToString()})

MyDirectoryEntry.CommitChanges()
MyUser.RefreshCache()

End Sub

Private Sub EnableAccount(ByVal AccountName As String)

Dim MyDirectoryEntry As DirectoryEntry
Dim MyDirectorySearcher As DirectorySearcher
Dim MyGroup As DirectoryEntry
Dim MyUser As DirectoryEntry
Dim MyUserAccountControl As Integer

MyDirectoryEntry = New DirectoryEntry("LDAP://" & AppSettings("LDAPPath"), AppSettings("Domain") & "\" & AppSettings("Administrator"), AppSettings("Password"))
MyDirectorySearcher = New DirectorySearcher(MyDirectoryEntry)
MyDirectorySearcher.Filter = "(samAccountName=" & AccountName & ")"
MyUser = New DirectoryEntry(MyDirectorySearcher.FindOne.GetDire ctoryEntry.Path)

MyUserAccountControl = MyUser.Properties("userAccountControl").Value

MyUser.Properties("userAccountControl").Value = MyUserAccountControl And Not ADS_UF_ACCOUNTDISABLE

MyDirectoryEntry.CommitChanges()
MyDirectoryEntry.RefreshCache()

End Sub

Private Sub DisableAccount(ByVal AccountName As String)

Dim MyDirectoryEntry As DirectoryEntry
Dim MyDirectorySearcher As DirectorySearcher
Dim MyGroup As DirectoryEntry
Dim MyUser As DirectoryEntry
Dim MyUserAccountControl As Integer

MyDirectoryEntry = New DirectoryEntry("LDAP://" & AppSettings("LDAPPath"), AppSettings("Domain") & "\" & AppSettings("Administrator"), AppSettings("Password"))
MyDirectorySearcher = New DirectorySearcher(MyDirectoryEntry)
MyDirectorySearcher.Filter = "(samAccountName=" & AccountName & ")"
MyUser = New DirectoryEntry(MyDirectorySearcher.FindOne.GetDire ctoryEntry.Path)

MyUserAccountControl = MyUser.Properties("userAccountControl").Value
MyUser.Properties("userAccountControl").Add(MyUser AccountControl Or ADS_UF_ACCOUNTDISABLE)

MyDirectoryEntry.CommitChanges()
MyDirectoryEntry.RefreshCache()

End Sub

Private Sub AddAccount(ByVal AccountName, ByVal Password)

CreateAccount(AccountName)
SetPassword(AccountName, Password)
EnableAccount(AccountName)
SetGroup(AccountName)

End Sub

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

End Class

Nov 18 '05 #1
0 1485

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
0
by: Luther Hert | last post by:
I solved my problem, but I am not sure whether or not I understand how I arrived at the solution. I leraned about and checked: IIS> creating virtual directories> configuring web extensions >...
0
by: Shawn Melton | last post by:
I am trying to do in order Create an Use Commit Change Set Passwor *Set Password No Expir *Set Cant Change Passwor Commit Change *Enable Use Commit Change
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
3
by: Jay-nospam | last post by:
Hi there, I am having trouble getting an ASP.NET web application to connect to another computer and passing the proper credentials and I hope someone can help me. I have a stand-alone Windows...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
1
by: Screenbert | last post by:
After finding nothing anywhere in google I am posting this so everyone can benefit by it. The formating is not pretty since I copied it from my word document, but you should benefit by it. ...
0
by: screenbert | last post by:
Managing DHCP Servers using C# They said it was impossible. It couldn't be done. But you can in fact manage DHCP servers using C#. This includes creating and deleting Scopes, SuperScopes,...
3
by: Brad | last post by:
I'm setting up my new pc with all my VS.net projects and I'm missing something.....something I've done many times before without problem. I have several asp.net apps accessing secure .net web...
25
by: jim | last post by:
I thought that I read somewhere that services don't (or can't) have forms. Is that true?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.