Question

VBscript - Need to Change a Small Item

Asked by: itsmevic

Hi,

  I have a script below that basically goes out and searches for accounts that have locked out 3 times within an 8 hour period.  I'd like to change the script now to within a 24 hour period.  Any help would be greatly appreciated.

Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
    strPath = Wscript.ScriptFullName
    strCommand = "%comspec% /k cscript  """ & strPath & """"
    objShell.Run(strCommand), 1, True
    Wscript.Quit
End If
 
strLogFolder = "\\server-abc\logs\ActLockout\Logs\"
'strLogFolder = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
 
' Set this to the maximum lockouts at which to trigger, inclusive
Const ActLockoutThreshold = 3
 
' Email variables:
strServer = "mailhost.abc.com"
strTo = "janedoe@abc.com"
strFrom = "johndoe@abc.com"
strSubject = "Account Lockout Status"
strBody = "Please see the account lockout status below:" & VbCrLf
 
Const ForReading = 1
Const adVarChar = 200
Const MaxCharacters = 255
Const adDouble = 5
 
boolThresholdReached = False
 
strShortDate = objShell.RegRead("HKCU\Control Panel\International\sShortDate")
If InStr(LCase(strShortDate), "d") < InStr(LCase(strShortDate), "m") Then
	strDateFormat = "dd/mm/yyyy"
Else
	strDateFormat = "mm/dd/yyyy"
End If
 
strDate = InputBox("Please enter the date of the files that you want to search" & VbCrLf & _
	"in " & strDateFormat & " format:", "Date to Search", strDateFormat)
 
If strDate <> "" And strDate <> strDateFormat Then
	
	dteDateFrom = CDate(strDate & " 00:00:00 AM")
	dteDateTo = CDate(strDate & " 11:59:59 PM")
	
	WScript.Echo "Parsing log folder " & strLogFolder & " for files created on " & strDate & VbCrLf & VbCrLf
 
	' Create the recordset to hold the entire data from each file parsed
	Set objData = CreateObject("ADOR.Recordset")
	objData.Fields.Append "Username", adVarChar, MaxCharacters
	objData.Fields.Append "DateTime", adVarChar, MaxCharacters
	objData.Fields.Append "DC", adVarChar, MaxCharacters
	objData.Fields.Append "PC", adVarChar, MaxCharacters
	objData.Open
	
	' Create the recordset to hold the information for each user once all of the files have been parsed
	Set objUsers = CreateObject("ADOR.Recordset")
	objUsers.Fields.Append "Username", adVarChar, MaxCharacters
	objUsers.Fields.Append "DistinguishedName", adVarChar, MaxCharacters
	objUsers.Fields.Append "ComputerName", adVarChar, MaxCharacters
	objUsers.Fields.Append "LockoutCount", adDouble
	objUsers.Open
 
	For Each objFile In objFSO.GetFolder(strLogFolder).Files
		If CDate(objFile.DateLastModified) > dteDateFrom And CDate(objFile.DateLastModified) < dteDateTo Then
			WScript.Echo "Parsing file " & objFile.Name & VbCrLf & VbCrLf
			 
			Set objFile = objFSO.OpenTextFile(objFile.Path, ForReading, False)
 
			strUsers = ";"
			 
			While Not objFile.AtEndOfStream
			    strLine = objFile.ReadLine
			    If strLine <> "" Then
				    arrLine = Split(LCase(strLine), ",")
				    objData.AddNew
				    objData("Username") = Trim(arrLine(0))
				    objData("DateTime") = Trim(arrLine(1)) & " " & Trim(arrLine(2))
				    objData("DC") = Trim(arrLine(3))
				    objData("PC") = Trim(arrLine(4))
				    objData.Update
				    If strUsers = "" Then
				    	strUsers = arrLine(0) & ";"
				    Else
				    	If InStr(strUsers, ";" & arrLine(0) & ";") = 0 Then strUsers = strUsers & arrLine(0) & ";"
				    End If
				End If
			Wend
			 
			objFile.Close
			 
			If Left(strUsers, 1) = ";" Then strUsers = Mid(strUsers, 2)
			If Right(strUsers, 1) = ";" Then strUsers = Left(strUsers, Len(strUsers) - 1)
 
		End If
	Next
	For Each strUser In Split(strUsers, ";")
		strUserDN = Get_LDAP_User_Properties("user", "samAccountName", strUser, "distinguishedName")
		objData.Filter = "Username='" & strUser & "'"
		objData.MoveFirst
		While Not objData.EOF
			objUsers.Filter = ""
			If Not objUsers.EOF Then objUsers.MoveFirst
		    objUsers.Filter = "Username='" & strUser & "' AND DistinguishedName='" & strUserDN & "' AND ComputerName='" & objData("PC") & "'"
		    If objUsers.EOF Then
			    objUsers.AddNew
			    objUsers("Username") = strUser
			    objUsers("DistinguishedName") = strUserDN
			    objUsers("ComputerName") = objData("PC")
			    objUsers("LockoutCount") = 1
			    objUsers.Update
			Else
				objUsers("LockoutCount") = objUsers("LockoutCount") + 1
			End If
			objData.MoveNext
		Wend
	Next
	objUsers.Filter = ""
	If Not objUsers.EOF Then objUsers.MoveFirst
	While Not objUsers.EOF
		If objUsers("LockoutCount") >= ActLockoutThreshold Then
			boolThresholdReached = True
			strBody = strBody & VbCrLf & "WARNING: " & objUsers("Username") & " (" & objUsers("DistinguishedName") & ") has been locked out of " & objUsers("ComputerName") & " " & objUsers("LockoutCount") & " times."
			WScript.Echo "WARNING: " & objUsers("Username") & " (" & objUsers("DistinguishedName") & ") has been locked out of " & objUsers("ComputerName") & " " & objUsers("LockoutCount") & " times."
		Else
			WScript.Echo objUsers("Username") & " (" & objUsers("DistinguishedName") & ") has been locked out of " & objUsers("ComputerName") & " " & objUsers("LockoutCount") & " times."
		End If
		objUsers.MoveNext
	Wend
Else
	WScript.Echo VbCrLf & VbCrLf & "Invalid date entered. Exiting script."
End If
 
' Now send the file
If boolThresholdReached = True Then
	SendEmail strServer, strTo, strFrom, strSubject, strBody
	WScript.Echo VbCrLf & VbCrLf & strBody & VbCrLf & VbCrLf
	WScript.Echo "Email has been sent."
Else
	WScript.Echo "No account changes have been made."
End If
 
WScript.Echo VbCrLf & VbCrLf & "Done"
 
Function Get_LDAP_User_Properties(strObjectType, strSearchField, strObjectToGet, strCommaDelimProps)
      
      ' This is a custom function that connects to the Active Directory, and returns the specific
      ' Active Directory attribute value, of a specific Object.
      ' strObjectType: usually "User" or "Computer"
      ' strSearchField: the field by which to seach the AD by. This acts like an SQL Query's WHERE clause.
      '				It filters the results by the value of strObjectToGet
      ' strObjectToGet: the value by which the results are filtered by, according the strSearchField.
      '				For example, if you are searching based on the user account name, strSearchField
      '				would be "samAccountName", and strObjectToGet would be that speicific account name,
      '				such as "jsmith".  This equates to "WHERE 'samAccountName' = 'jsmith'"
      '	strCommaDelimProps: the field from the object to actually return.  For example, if you wanted
      '				the home folder path, as defined by the AD, for a specific user, this would be
      '				"homeDirectory".  If you want to return the ADsPath so that you can bind to that
      '				user and get your own parameters from them, then use "ADsPath" as a return string,
      '		jData("PC") & "'"
		    If objUsers.EOF Then
			    objUsers.AddNew
			    objUsers("Username") = strUser
			    objUsers("DistinguishedName") = strUserDN
			    objUsers("ComputerName") = objData("PC")
			    objUsers("LockoutCount") = 1
			    objUsers.Update
			Else
				objUsers("LockoutCount") = objUsers("LockoutCount") + 1
			End If
			objData.MoveNext
		Wend
	Next
	objUsers.Filter = ""
	If Not objUsers.EOF Then objUsers.MoveFirst
	While Not objUsers.EOF
		If objUsers("LockoutCount") >= ActLockoutThreshold Then
			boolThresholdReached = True
			strBody = strBody & VbCrLf & "WARNING: " & objUsers("Username") & " (" & objUsers("DistinguishedName") & ") has been locked out of " & objUsers("ComputerName") & " " & objUsers("LockoutCount") & " times."
			WScript.Echo "WARNING: " & objUsers("Username") & " (" & objUsers("DistinguishedName") & ") has been locked out of " & objUsers("ComputerName") & " " & objUsers("LockoutCount") & " times."
		Else
			WScript.Echo objUsers("Username") & " (" & objUsers("DistinguishedName") & ") has been locked out of " & objUsers("ComputerName") & " " & objUsers("LockoutCount") & " times."
		End If
		objUsers.MoveNext
	Wend
Else
	WScript.Echo VbCrLf & VbCrLf & "Invalid date entered. Exiting script."
End If
 
' Now send the file
If boolThresholdReached = True Then
	SendEmail strServer, strTo, strFrom, strSubject, strBody
	WScript.Echo VbCrLf & VbCrLf & strBody & VbCrLf & VbCrLf
	WScript.Echo "Email has been sent."
Else
	WScript.Echo "No account changes have been made."
End If
 
WScript.Echo VbCrLf & VbCrLf & "Done"
 
Function Get_LDAP_User_Properties(strObjectType, strSearchField, strObjectToGet, strCommaDelimProps)
      
      ' This is a custom function that connects to the Active Directory, and returns the specific
      ' Active Directory attribute value, of a specific Object.
      ' strObjectType: usually "User" or "Computer"
      ' strSearchField: the field by which to seach the AD by. This acts like an SQL Query's WHERE clause.
      '				It filters the results by the value of strObjectToGet
      ' strObjectToGet: the value by which the results are filtered by, according the strSearchField.
      '				For example, if you are searching based on the user account name, strSearchField
      '				would be "samAccountName", and strObjectToGet would be that speicific account name,
      '				such as "jsmith".  This equates to "WHERE 'samAccountName' = 'jsmith'"
      '	strCommaDelimProps: the field from the object to actually return.  For example, if you wanted
      '				the home folder path, as defined by the AD, for a specific user, this would be
      '				"homeDirectory".  If you want to return the ADsPath so that you can bind to that
      '				user and get your own parameters from them, then use "ADsPath" as a return string,
      '				then bind to the user: Set objUser = GetObject("LDAP://" & strReturnADsPath)
      
      ' Now we're checking if the user account passed may have a domain already specified,
      ' in which case we connect to that domain in AD, instead of the default one.
      If InStr(strObjectToGet, "\") > 0 Then
            arrGroupBits = Split(strObjectToGet, "\")
            strDC = arrGroupBits(0)
            strDNSDomain = strDC & "/" & "DC=" & Replace(Mid(strDC, InStr(strDC, ".") + 1), ".", ",DC=")
            strObjectToGet = arrGroupBits(1)
      Else
      ' Otherwise we just connect to the default domain
            Set objRootDSE = GetObject("LDAP://RootDSE")
            strDNSDomain = objRootDSE.Get("defaultNamingContext")
      End If
                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-15 at 14:30:27ID24816470
Topics

VB Script

,

Active Directory

Participating Experts
1
Points
500
Comments
4

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. lockout vbscript
    I would like to have a vbscript that uses a timer that checks every 30 minutes in the network, if there is any computer locked out and have it send me an email to myemail@mydomain.com Thanks
  2. Calc Start Stop in 24 Hour Period
    Working with a MsAccess 2002, Win2k; Have a database table that has these fields; 1) OP_DATE (mm-dd-yyyy) 2) OP_HOUR (0-23) 3) OP_TIME (1 or 0) 4) UNITID (name - text) If there is a 1 in the OP_TIME this means that the unit was ON if it is a 0 then it is OFF at that given h...
  3. URGENT: Server locks up after a period of hours.
    Up until recently this winodws 2000 server had been working fine for the company I am at. There were no problems, everything ran smoothly. As of yesturday it started to lock up and random periods of time. 3 hours seems to be the smallest amount of time. The network users run ...
  4. Looking for an automated script to delete files after a 24 h…
    I am looking to create an automated script for our company FTP site that will delete files that are created in a folder after a 24 hour period. I would like it to be done in VB Script as I am kind of familiar with it. I have been searching the web and have been having some tr...
  5. Validate date within 24 hour period
    Hi, I need to be able to validate 3 date fields $month, $day, $year and ensure (IF statement) that they are not within a 24 hour period of "today's date" when posted. I'm assuming I'll have to concatenate the three variables and then challenge them against: $t...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: RobSampsonPosted on 2009-10-15 at 15:29:37ID: 25585541

Hi, the script searches log files for one particular day, and doesn't appear to be time restricted other than that, so it reports on the lockout count per day, in effect.

If you want it to span a couple of days, we can add a loop and add a start day and end day if you like.

Regards,

Rob.

 

by: itsmevicPosted on 2009-10-15 at 23:19:08ID: 25587345

Yeah I went back and looked at it again, the search is actually for a 24 hour period so actually we probably wouldn't need to do anything to it since it will only be ran once daily it will cover basically that 24 hour period I'm thinking.  I'll get back to you on this Rob, tomorrow, need to do a bit more research on it.

 

by: RobSampsonPosted on 2009-10-16 at 04:13:54ID: 25588392

Sure, no problem.

Rob.

 

by: itsmevicPosted on 2009-10-19 at 18:58:33ID: 31641887

I think it will suffice as it is Rob.  Thanks greatly for all your help.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...