473,545 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to lock/unlock an ad account

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

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

Imports System.Director yServices

'Lock:

Public Function lockAcct(ByVal acct2Lock As String) As Boolean

Dim blnreturn As Boolean = False

Dim i As Integer = 0

Dim path As String = gstrActiveDirec tory

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.NativeObje ct

'line2 section is to confirm the account has been locked

Line2:

Dim user2 As DirectoryEntry = adUser(acct2Loc k)

If Convert.ToBoole an(user2.Invoke Get("IsAccountL ocked")) 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(ByVa l userid As String) As String

Dim strReturn As String = ""

Dim path As String = gstrActiveDirec tory

Dim entry As DirectoryEntry = New DirectoryEntry( path)

Try

Dim searcher As New
System.Director yServices.Direc torySearcher(en try)

searcher.Filter =
"(&(objectClass =user)(objectCa tegory=person)( sAMAccountName= " & userid &
"))"

searcher.Proper tiesToLoad.Add( "adspath")

Dim Result As System.Director yServices.Searc hResult =
searcher.FindOn e()

If Not Result Is Nothing Then

Dim user As New
DirectoryServic es.DirectoryEnt ry(Result.Path)

Try

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

user.CommitChan ges()

user.Close()

strReturn = "successful "

Catch err As UnauthorizedAcc essException

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******** ********@TK2MSF TNGP03.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
4511
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 threads / processes can not lock this file again. And I want that all threads / processes wait until first thread frees lock by calling...
14
3810
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 + 64)) Next Lock(1, 5, 10)
8
3999
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 specific business needs When such a lock is made for a transaction (this code is in the web service) and the handhelds are terminated abnormally (cold...
2
15772
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: Lock(KEY, SQLCODE) - to create a lock. Returns 0 on success, 1 if a lock already exists and -1 on failure with SQLCODE. There is no necessity to use...
1
1863
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 request comes in before app start is complete does it wait for app start to complete or does it go straight to BeginRequest? It appears in some cases...
5
704
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, even after the first process is finished with it, except in the case where the first process crashes. In pseudo code.. * Open file with exclusive...
45
4357
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
4093
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 collection) { yield return obj;
6
5367
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 with the application lock and why it's in use (see lines 19 - 21)? public class QuoteClass : UserControl { public HtmlGenericControl divQuote; ...
0
7415
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7675
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. ...
1
7440
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...
0
7775
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...
0
4963
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...
0
3470
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...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1902
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
0
726
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...

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.