473,779 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Directory Services saves some settings and not others

#Region "Imports

Imports ADSSECURITYLi
Imports System.Diagnost ic
Imports Scriptin
Imports ActiveD
Imports System.Director yService
Imports System.Configur ation.Configura tionSetting
Imports System.I

#End Regio

Public Class Utilit
Inherits System.Web.UI.P ag

#Region "Constants

Const ADS_UF_SCRIPT = &H
Const ADS_UF_ACCOUNTD ISABLE = &H
Const ADS_UF_HOMEDIR_ REQUIRED = &H
Const ADS_UF_LOCKOUT = &H1
Const ADS_UF_PASSWD_N OTREQD = &H2
Const ADS_UF_PASSWD_C ANT_CHANGE = &H4
Const ADS_UF_ENCRYPTE D_TEXT_PASSWORD _ALLOWED = &H8
Const ADS_UF_TEMP_DUP LICATE_ACCOUNT = &H10
Const ADS_UF_NORMAL_A CCOUNT = &H20
Const ADS_UF_INTERDOM AIN_TRUST_ACCOU NT = &H80
Const ADS_UF_WORKSTAT ION_TRUST_ACCOU NT = &H100
Const ADS_UF_SERVER_T RUST_ACCOUNT = &H200
Const ADS_UF_DONT_EXP IRE_PASSWD = &H1000
Const ADS_UF_MNS_LOGO N_ACCOUNT = &H2000
Const ADS_UF_SMARTCAR D_REQUIRED = &H4000
Const ADS_UF_TRUSTED_ FOR_DELEGATION = &H8000
Const ADS_UF_NOT_DELE GATED = &H10000
Const ADS_UF_USE_DES_ KEY_ONLY = &H20000
Const ADS_UF_DONT_REQ UIRE_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.EventArg s) Handles MyBase.Loa

Dim AccountName as strin
Dim Password as Strin

AccountName = "SEA1010
Password = "123456789

AddAccount(Acco untName, Password

End Su

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

Dim MyDirectoryEntr y As DirectoryEntr
Dim MyDirectorySear cher As DirectorySearch e
Dim MyGroup As DirectoryEntr
Dim MyUser As DirectoryEntr
Dim MyUserAccountCo ntrol As Intege

MyDirectoryEntr y = New DirectoryEntry( "LDAP://" & AppSettings("LD APPath"), AppSettings("Do main") & "\" & AppSettings("Ad ministrator"), AppSettings("Pa ssword")
MyDirectorySear cher = New DirectorySearch er(MyDirectoryE ntry
MyDirectorySear cher.Filter = "(samAccountNam e=" & AccountName & ")
MyUser = New DirectoryEntry( MyDirectorySear cher.FindOne.Ge tDirectoryEntry .Path
MyUser.Authenti cationType = AuthenticationT ypes.Secur
MyUser.Invoke(" SetPassword", New Object() {Password}

MyUserAccountCo ntrol = MyUser.Properti es("userAccount Control").Valu
MyUser.Properti es("userAccount Control").Value = MyUserAccountCo ntrol Or ADS_UF_DONT_EXP IRE_PASSW
MyUser.Properti es("userAccount Control").Value = MyUserAccountCo ntrol Or ADS_UF_PASSWD_C ANT_CHANG

MyDirectoryEntr y.CommitChanges (
MyDirectoryEntr y.RefreshCache(

End Su

Private Sub CreateAccount(B yVal AccountName As String

Dim MyDirectoryEntr y As DirectoryEntr
Dim MyDirectorySear cher As DirectorySearch e
Dim MyGroup As DirectoryEntr
Dim MyUser As DirectoryEntr

MyDirectoryEntr y = New DirectoryEntry( "LDAP://" & AppSettings("LD APPath"), AppSettings("Do main") & "\" & AppSettings("Ad ministrator"), AppSettings("Pa ssword")
MyUser = MyDirectoryEntr y.Children.Add( "cn=" & AccountName & ",ou=" & AppSettings("LD APOU"), "user"
MyUser.Properti es("sn").Add(Ac countName
MyUser.Properti es("displayName ").Add(AccountN ame
MyUser.Properti es("samAccountN ame").Add(Accou ntName
MyUser.Properti es("homeDirecto ry").Add(AppSet tings("FTPDirec toryPath") & AccountName
MyUser.Properti es("accountExpi res").Add(0

MyUser.CommitCh anges(
MyUser.RefreshC ache(

End Su

Private Sub SetGroup(ByVal AccountName As String

Dim MyDirectoryEntr y As DirectoryEntr
Dim MyDirectorySear cher As DirectorySearch e
Dim MyGroup As DirectoryEntr
Dim MyUser As DirectoryEntr

MyDirectoryEntr y = New DirectoryEntry( "LDAP://" & AppSettings("LD APPath"), AppSettings("Do main") & "\" & AppSettings("Ad ministrator"), AppSettings("Pa ssword")
MyDirectorySear cher = New DirectorySearch er(MyDirectoryE ntry
MyDirectorySear cher.Filter = "(samAccountNam e=" & AccountName & ")"
MyUser = New DirectoryEntry( MyDirectorySear cher.FindOne.Ge tDirectoryEntry .Path)

MyDirectoryEntr y = New DirectoryEntry( "LDAP://" & AppSettings("LD APPath") & "/CN=" & AppSettings("LD APCN") & ",OU=" & AppSettings("LD APOU") & " , " & AppSettings("LD APDCPath"), AppSettings("Do main") & "\" & AppSettings("Ad ministrator"), AppSettings("Pa ssword"))
MyDirectoryEntr y.Invoke("Add", New Object() {MyUser.Path.To String()})

MyDirectoryEntr y.CommitChanges ()
MyUser.RefreshC ache()

End Sub

Private Sub EnableAccount(B yVal AccountName As String)

Dim MyDirectoryEntr y As DirectoryEntry
Dim MyDirectorySear cher As DirectorySearch er
Dim MyGroup As DirectoryEntry
Dim MyUser As DirectoryEntry
Dim MyUserAccountCo ntrol As Integer

MyDirectoryEntr y = New DirectoryEntry( "LDAP://" & AppSettings("LD APPath"), AppSettings("Do main") & "\" & AppSettings("Ad ministrator"), AppSettings("Pa ssword"))
MyDirectorySear cher = New DirectorySearch er(MyDirectoryE ntry)
MyDirectorySear cher.Filter = "(samAccountNam e=" & AccountName & ")"
MyUser = New DirectoryEntry( MyDirectorySear cher.FindOne.Ge tDirectoryEntry .Path)

MyUserAccountCo ntrol = MyUser.Properti es("userAccount Control").Value

MyUser.Properti es("userAccount Control").Value = MyUserAccountCo ntrol And Not ADS_UF_ACCOUNTD ISABLE

MyDirectoryEntr y.CommitChanges ()
MyDirectoryEntr y.RefreshCache( )

End Sub

Private Sub DisableAccount( ByVal AccountName As String)

Dim MyDirectoryEntr y As DirectoryEntry
Dim MyDirectorySear cher As DirectorySearch er
Dim MyGroup As DirectoryEntry
Dim MyUser As DirectoryEntry
Dim MyUserAccountCo ntrol As Integer

MyDirectoryEntr y = New DirectoryEntry( "LDAP://" & AppSettings("LD APPath"), AppSettings("Do main") & "\" & AppSettings("Ad ministrator"), AppSettings("Pa ssword"))
MyDirectorySear cher = New DirectorySearch er(MyDirectoryE ntry)
MyDirectorySear cher.Filter = "(samAccountNam e=" & AccountName & ")"
MyUser = New DirectoryEntry( MyDirectorySear cher.FindOne.Ge tDirectoryEntry .Path)

MyUserAccountCo ntrol = MyUser.Properti es("userAccount Control").Value
MyUser.Properti es("userAccount Control").Add(M yUserAccountCon trol Or ADS_UF_ACCOUNTD ISABLE)

MyDirectoryEntr y.CommitChanges ()
MyDirectoryEntr y.RefreshCache( )

End Sub

Private Sub AddAccount(ByVa l AccountName, ByVal Password)

CreateAccount(A ccountName)
SetPassword(Acc ountName, Password)
EnableAccount(A ccountName)
SetGroup(Accoun tName)

End Sub

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

End Sub

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

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

#End Region

End Class

Nov 18 '05 #1
0 1514

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

Similar topics

9
10904
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 the wheel, right? Everything so far is working well with the Active Directory. The problem I am having is with adding File Permissions to a directory. I am currently using some code courtesy of "Willy Denoyette "
0
1286
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 > AspNet installation> and installing the lcoalhost web site. When I used Aspnet_regiis.exe to repair IIS Mappings for Asp.Net, my c:\drive directory was altered.
0
346
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
5803
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 SQL DATABASE, probably by the click of a button. Is this possible? & what is the BEST APPROACH for doing this? & also if any links are there do tell those to me too coz I have no idea how to go about doing it.
3
2622
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 2003 Server, ServerA, running as a Web Server that uses ASP.NET. The default.aspx file tries to access a file in a share on another computer, ServerB. ServerA and ServerB are on the same domain and are both running Windows 2003 Server.
53
4758
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, and .Net2005 code. I'm developing in vb.net 2005. This test sub just reads an input text file, writing out records to another text file, eliminating records that have a '99' in them (it is similar to a CSV file). Some of my concerns are:
1
11140
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. 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, Reservations, Exclusions, Options and so forth. Since the dll...
0
12359
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, Reservations, Exclusions, Options and so forth. Since the dll that is used was written several years ago by Microsoft, you cannot manage things on the DNS tab when looking at a reservation and few things such as that however it gives you main things you...
3
7756
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 services (secure meaning windows authentication credentials must be used to access the web services). The problem is that when the web apps attempt to access a web service they are receiving 401: unathorized. - The apps are all running on web...
25
1252
by: jim | last post by:
I thought that I read somewhere that services don't (or can't) have forms. Is that true?
0
10138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.