Solved

Simple vbs Question: Modifing a script to prompt for user input.

Posted on 2008-10-02
4
245 Views
Last Modified: 2012-05-05
This is a very simple question. Is it possible to modify the script below to prompt for a username and then disable that username? I have absolutely zero experience in vbs so I do not even know where to begin. Any help would be great!
Const ADS_UF_ACCOUNTDISABLE = 2

 

Set objUser = GetObject _

("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

intUAC = objUser.Get("userAccountControl")

 

objUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE

objUser.SetInfo

Open in new window

0
Comment
Question by:Joseph Moody
  • 2
4 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 22627463
Try this...test it first with a test user...
On Error Resume Next
 

Const ADS_SCOPE_SUBTREE = 2

Const ADS_UF_ACCOUNTDISABLE = 2

strUser= InputBox("Enter username")
 

Set objConnection = CreateObject("ADODB.Connection")

Set objCommand =   CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"

objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection
 

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 

objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://dc=fabrikam,dc=com' WHERE objectCategory='user' " & _

        "AND samaccountname = '" & strUser & "'" 

Set objRecordSet = objCommand.Execute
 

objRecordSet.MoveFirst

Do Until objRecordSet.EOF

    strDN = objRecordSet.Fields("distinguishedName").Value

    objRecordSet.MoveNext

Loop
 

Set objUser = GetObject("LDAP://" & strDN)
 

intUAC = objUser.Get("userAccountControl")

objUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE

objUser.SetInfo

Open in new window

0
 
LVL 7

Expert Comment

by:Paul Tozer
ID: 22627474
try
dim fname

fname=InputBox("Enter your name:")

Const ADS_UF_ACCOUNTDISABLE = 2

 

Set objUser = GetObject _

("LDAP://cn=" & fname & ",ou=management,dc=fabrikam,dc=com")

intUAC = objUser.Get("userAccountControl")

 

objUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE

objUser.SetInfo

Open in new window

0
 
LVL 22

Author Closing Comment

by:Joseph Moody
ID: 31502512
That worked perfect! And now I have a good example for any other scripts that I made need to do this to in the future.

Thanks again!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22627613
Happy to help - thanx for the grade! :^)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now