473,395 Members | 1,637 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,395 software developers and data experts.

how to lock/unlock an ad account

Anybody has any ideas?
Jul 8 '08 #1
2 5358
ASP.NET 2.0 Membership, Roles and Profiles provided support for locking and
unlocking user accounts.

"Lidia" <ll*@omnitrans.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Anybody has any ideas?
Jul 8 '08 #2
Share my code to solve the problem mentioned above:

Imports System.DirectoryServices

'Lock:

Public Function lockAcct(ByVal acct2Lock As String) As Boolean

Dim blnreturn As Boolean = False

Dim i As Integer = 0

Dim path As String = gstrActiveDirectory

Dim user As DirectoryEntry = Nothing

Try

'since it's hard to use code to lock an account, use 4 attempts
to login and let AD handle it

'line1 section is to try to login using 1 as password

Line1:

i = i + 1

user = New DirectoryEntry(path, acct2Lock, 1)

Dim nativeObject As Object = user.NativeObject

'line2 section is to confirm the account has been locked

Line2:

Dim user2 As DirectoryEntry = adUser(acct2Lock)

If Convert.ToBoolean(user2.InvokeGet("IsAccountLocked ")) Then

blnreturn = True

End If

Catch ex As Exception

If i < 4 Or i = 4 Then

GoTo Line1

End If

GoTo Line2

End Try

Return blnreturn

End Function

'Unlock:

Public Function unlockAcct(ByVal userid As String) As String

Dim strReturn As String = ""

Dim path As String = gstrActiveDirectory

Dim entry As DirectoryEntry = New DirectoryEntry(path)

Try

Dim searcher As New
System.DirectoryServices.DirectorySearcher(entry)

searcher.Filter =
"(&(objectClass=user)(objectCategory=person)(sAMAc countName=" & userid &
"))"

searcher.PropertiesToLoad.Add("adspath")

Dim Result As System.DirectoryServices.SearchResult =
searcher.FindOne()

If Not Result Is Nothing Then

Dim user As New
DirectoryServices.DirectoryEntry(Result.Path)

Try

user.Properties("LockOutTime").Value = 0 'unlock account

user.CommitChanges()

user.Close()

strReturn = "successful"

Catch err As UnauthorizedAccessException

strReturn = err.Message

End Try

Else

strReturn = "No such user in the active directory"

End If

Catch ex As Exception

'do something here

End Try

Return strReturn

End Function

"Lidia" <ll*@omnitrans.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Anybody has any ideas?

Jul 10 '08 #3

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

Similar topics

0
by: John | last post by:
I've got multiple threads and processes that write to same file. Before writing all threads / processes first lock part of file and then write to file. If one thread / process locks file, another...
14
by: Gary Nelson | last post by:
Anyone have any idea why this code does not work? FileOpen(1, "c:\JUNK\MYTEST.TXT", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Shared) Dim X As Integer For X = 1 To 26 FilePut(1, Chr(X +...
8
by: Komandur Kannan | last post by:
We have a smart device application running on handhelds(Symbol MC9000G). The backend is Oracle and a middle tier web services development done in Vb.net. We use pessimistic Locking due to...
2
by: adri4n | last post by:
as wat ive mentioned in the title.. im would like to know whether the a particular record/table is being locked in my program. some of the methods which i would like to develop are as below: ...
1
by: APA | last post by:
In the Application_Start event I load several static variables with data from the database that are critical to the execution of the application. My question is that during app start if a second...
5
by: pgdown | last post by:
Hi, I have several processes accessing files from one folder, but only one process should ever access each file. Once one process has the file, no other process should be allowed to access it,...
45
by: Chris Forone | last post by:
hello group, is there a chance for other functions to get the lock if i have following loop: while (running) { Lock local(mutex); }
8
by: Clive Dixon | last post by:
Are there any issues I should be worried about when using C# 2.0 iterators in conjunction with lock, i.e. public IEnumerator GetEnumerator() { lock (lockObject) { foreach (object obj in...
6
by: DaveRook | last post by:
Hi I have some code from a friend and I don't understand why they have used the application lock feature! I understand this produces a random quote, but can some one explain to me what happens...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.