473,503 Members | 1,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AD query - search AD for valid username w/input box

Lookin4Toons
3 New Member
Trying to create a text box w/user input to enter a suggested user name and query AD to see if the name is available. This is for HR users who do not have access to the Admin tools to open the container. Can this be written another way to "prompt" for user input somewhere else in the script?
Thank you -

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
strUSER = InputBox("Please put the desired User Name:","USER")
If strUSER = "" Then
WScript.Echo "No User Name entered. Program aborted."
Wscript.Quit
End If
On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = ("ADsDSOObject")
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
objUser = GetObject ("'LDAP://OU=xx,dc=xx,dc=xx,dc=xx'" & obj.User.UserName)
objCommand.CommandText = "SELECT samAccountName FROM " & _
"'LDAP://OU=xx,dc=xx,dc=xx,dc=xx'" & _
"WHERE samAccountName = %strUser%"
objCommand.Properties("SearchScope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount = 0 Then
Wscript.Echo "The Account name is not being used."
Else
Wscript.Echo "The Account name is being used. Please choose another name."
End If
Jun 15 '09 #1
2 3287
Lookin4Toons
3 New Member
Figured it out after several attempts:
Now I need to figure out if the name exists, how to loop back to check another

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Dim Fname
strFname = InputBox("Please put the desired User Name:",Fname)
If strFname = "" Then
WScript.Echo "No User Name entered. Program aborted."
Wscript.Quit
End If
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = ("ADsDSOObject")
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "SELECT ScriptPath FROM 'LDAP://OU=xxx,dc=ad,dc=xx,dc=xxx' WHERE objectCategory='user'" & _
"AND sAMAccountName='" & strFname & "'"
objCommand.Properties("SearchScope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount = 0 Then
Wscript.Echo "The Account:"&strFname& " name is not being used."
Else
Wscript.Echo "The Account "&strFname& " is being used. Please choose another name."
End If
Jun 15 '09 #2
Lookin4Toons
3 New Member
Now that I have figured out how to get the basics, how do I insert a If Then to loop it back if they want to retry if they name exists.
Same question if the name is OK if they would like to check another name.
Should I use the MsgBox at this point?
Jun 16 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3950
by: Mike Cocker | last post by:
Hello, I'm quite weak at PHP, so I was hoping to get some help understanding the below code. First off, I'm trying to create a "query form" that will allow me to display the results on my...
2
3413
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
5
1996
by: T_2k | last post by:
I am trying to setup a search facility, such that anything selected in any of 5 comboboxes is used as criteria unless null or "". I only want to get back results where ALL selections are in a...
4
9002
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
2
2708
by: salvadorvp | last post by:
Hi, I wonder If somebody has experience this or could point me in the right direction: I have the following script (commented out just to use the username): // Check username and password //...
2
1646
by: studentfromhell | last post by:
These mesages appeared... what should I do? script is below the error messages... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in...
3
3001
by: =?Utf-8?B?YXppZWdsZXI=?= | last post by:
Hello, everybody. I'd like to do this: For a big program (a web service) I need information about the usergroups an active-directory-user is member of. To be more precise, I need to know if a...
5
3691
by: agarwalsrushti | last post by:
hi, This is my the search code i have tried it works well with the fiels stores as string in the database. But i have stored the qualification and specialization as int in database. Each selected...
0
7084
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
7278
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
7328
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...
0
7458
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...
0
5578
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,...
0
4672
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...
0
3167
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...

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.