Solved

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

Posted on 2008-10-02
4
244 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

13 Experts available now in Live!

Get 1:1 Help Now