473,696 Members | 1,742 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 1506

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

Similar topics

9
10896
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
1281
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
5793
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
2616
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
4662
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
11132
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
12352
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
7754
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
1238
by: jim | last post by:
I thought that I read somewhere that services don't (or can't) have forms. Is that true?
0
8658
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9005
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
8873
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,...
0
8847
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4352
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
4606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1989
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.