1984 Super Bowl ad
The Original 1984 Macintosh Introduction
I've been working on code to figure out how many days of events are in an each event log on a given system. I started out by using two articles from Microsoft's Hey, Scripting Guy!:
How Can I Find the Date of the Oldest Event in an Event Log?
How Can I Retrieve Information About the Latest Event Added to an Event Log?
The Oldest Event seemed to work:
1: strComputer = "."
2: Set objWMIService = GetObject("winmgmts:{(Security)}\\" & strComputer & "\root\cimv2")
3:
4: Wscript.Echo "System"
5: Set colEvents = objWMIService.ExecQuery _
6: ("Select * from Win32_NTLogEvent Where Logfile = 'System' " & _
7: "AND RecordNumber = 1")
8:
9: For Each objEvent in colEvents
10: Wscript.Echo "Time Written: " & objEvent.TimeWritten
11: Next
This seems to work. I duplicated lines 4 through 11, for the event logs Application and Security, all seemed okay. (Yeah I know redundant code, but sometimes it is just easiest.)
C:\Data2>cscript EventLogOldest.vbs Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved. |
All of this testing was on Windows XP SP3. I then tried it on Windows 2003 SP2:
C:\data2>cscript EventLogOldest.vbs Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. |
Hmm, what's going on here. Well, via another script, I figured out that the first event log record isn't always 1. Well it is, but the oldest event log entry in a given log isn't always record 1. See, as a system runs, it will remove old entries as the event log fills up. Thus the oldest record number slowly increments as the old records fall off and new records are added.
The following script, iterates through each event record on a server. It Looks at the record number and log file name and records the oldest and newest record for each log file. It then dumps out the desired information.
1: 'EventLogRecNumbers.vbs
2: strComputer = "."
3: Dim HighEvent
4: Dim LowEvent
5: Dim HighEventDate
6: Dim LowEventDate
7: Set HighEvent = CreateObject("Scripting.Dictionary")
8: Set LowEvent = CreateObject("Scripting.Dictionary")
9: Set HighEventDate = CreateObject("Scripting.Dictionary")
10: Set LowEventDate = CreateObject("Scripting.Dictionary")
11: ' Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
12: Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}\\" & strComputer & "\root\cimv2")
13: Set colItems = objWMIService.ExecQuery( _
14: "SELECT * FROM Win32_NTLogEvent ",,48)
15:
16: For Each objItem in colItems
17: currlogfile = objItem.Logfile
18: currlogrecord = clng(objItem.RecordNumber)
19: If not HighEvent.Exists(currlogfile) then
20: HighEvent.Add currlogfile, currlogrecord
21: HighEventDate.Add currlogfile,objItem.TimeWritten
22: else if currlogrecord > HighEvent.item(currlogfile) then
23: HighEvent.Item(currlogfile) = currlogrecord
24: HighEventDate.Item(currlogfile) = objItem.TimeWritten
25: End If
26: End If
27: If not LowEvent.Exists(currlogfile) then
28: LowEvent.Add currlogfile, currlogrecord
29: LowEventDate.Add currlogfile,objItem.TimeWritten
30: else if currlogrecord < LowEvent.item(currlogfile) then
31: LowEvent.Item(currlogfile) = currlogrecord
32: LowEventDate.Item(currlogfile) = objItem.TimeWritten
33: End If
34: End If
35: Next
36:
37: For Each ELog in HighEvent.Keys
38: Wscript.Echo "EventLog: " & ELog
39: Wscript.Echo " High Record: " & HighEvent.Item(ELog)
40: Wscript.Echo " Low Record: " & LowEvent.Item(ELog)
41: Wscript.Echo " Newest Date: " & WMIDateStringToDate(HighEventDate.Item(ELog))
42: Wscript.Echo " Oldest Date: " & WMIDateStringToDate(LowEventDate.Item(ELog))
43: Wscript.Echo " Days: " & DateDiff("d",WMIDateStringToDate(LowEventDate.Item(ELog)),WMIDateStringToDate(HighEventDate.Item(ELog)))
44: Next
45:
46: Function WMIDateStringToDate(dtmInstallDate)
47: WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _
48: Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _
49: & " " & Mid (dtmInstallDate, 9, 2) & ":" & _
50: Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _
51: 13, 2))
52: End Function
This works both on my fairly new XP SP3 system, as well as a Windows 2003 SP2 system. The draw back, is that because the script iterates through every event entry in the logs, it takes a while to come up with the answer. It isn't the most efficient, and I welcome alternative ways of performing this tasks. A plus is that it shows all event logs, not just the common Application, System and Security.
C:\>cscript EventLogRecNumbers.vbs Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. |
Saw this over on Life On the Wicked Stage: Act 2
Below you will find my schedule for Mon - Wed at DEC 2008. The sessions I've decided to go on are in light turquoises. If I haven't decided, there will be two white squares.
I am concentrating on the AD aspects of the conference and ignoring ILM and Federated Identity.
There is also a Welcome reception on Sunday.
This one was fun. Although, I knew what a Prime number is, I don't think I've ever learned methods to find them. The method I used is fine for a small number, but really wouldn't scale.
Advanced Event 6 in the Microsoft Scripting Games 2008.
1: '*********************************************************************
2: ' Script Name: Event6.vbs
3: ' Version: 1.0
4: ' Author: Perry Harris (PHactotum)
5: ' Updated: 8:45 AM Tuesday, February 26, 2008
6: ' Purpose: Solves the 2008 winter Scripting Games Advance
7: ' Event 6: Prime Time
8: '
9: ' Usage: cscript Event6.vbs
10: ' Notes:
11: ' Keywords:
12: ' versioning: 1.0 Original release
13: '*********************************************************************
14: Option Explicit
15: Dim StopPoint,StartPoint,i,j
16: Dim Primes
17: StopPoint = 200
18: StartPoint = 2
19: redim Primes(StopPoint + 1)
20: For i = StartPoint to StopPoint
21: Primes(i) = True
22: Next
23: For i = StartPoint to StopPoint
24: If Primes(i) = True then
25: WScript.StdOut.WriteLine i
26: End If
27: for j = i to StopPoint
28: If i*j <=StopPoint then Primes (i*j) = False
29: Next
30: Next
31:
32:
I'm not sure how well this one went. I ran out of time and I'm not very good with regular expressions. Advanced Event 5 for the Microsoft Scripting Games 2008.
1: '*********************************************************************
2: ' Script Name: Event5.vbs
3: ' Version: 1.0
4: ' Author: Perry Harris (PHactotum)
5: ' Updated: 10:45 AM Tuesday, February 26, 2008
6: ' Purpose: Solves the 2008 winter Scripting Games Advance
7: ' Event 5: You Call That a Strong Password?
8: '
9: ' Usage: cscript Event5.vbs
10: ' Notes:
11: ' Keywords:
12: ' versioning: 1.0 Original release
13: '*********************************************************************
14: 'Option Explicit
15: Const ForReading = 1
16: Dim strPassword
17: Dim intPassScore
18: Dim objRegEx
19: Dim objFS, objFile
20:
21: Set objRegEx = CreateObject("VBScript.RegExp")
22: intPassScore = 13
23:
24: if WScript.Arguments.Count < 1 then
25: WScript.StdOut.Write "Please enter your password to test: "
26: strPassword = WScript.StdIn.ReadLine
27: else
28: strPassword = WScript.Arguments(0)
29: end if
30:
31: 'Open and read our WordList, we'll need this for some of the tests.
32: Set objFS = CreateObject("Scripting.FileSystemObject")
33: Set objFile = objFS.OpenTextFile("C:\Scripts\wordlist.txt", ForReading)
34:
35: strAll = objFile.Readall
36:
37: ' Test one: Make sure that the password is not an actual word.
38: objRegEx.Pattern = ucase(strPassword) & "\r\n"
39: Set colMatches = objRegEx.Execute(ucase(strAll))
40:
41: If colMatches.Count > 0 Then
42: Wscript.StdOut.WriteLine "Password is found in the dictionary"
43: intPassScore = intPassScore - 1
44: End If
45:
46: ' Test two: Make sure that the password, minus the last letter, is not an actual word.
47: objRegEx.Pattern = ucase(left(strPassword,len(strPassword)-1)) & "\r?\n"
48: Set colMatches = objRegEx.Execute(ucase(strAll))
49:
50: If colMatches.Count > 0 Then
51: Wscript.StdOut.WriteLine "Password, minus the last letter, is found in the dictionary"
52: intPassScore = intPassScore - 1
53: End If
54:
55: ' Test three: Make sure that the password, minus the first letter, is not an actual word.
56: objRegEx.Pattern = "\r\n" & ucase(right(strPassword,len(strPassword)-1)) & "\r\n"
57: Set colMatches = objRegEx.Execute(ucase(strAll))
58:
59: If colMatches.Count > 0 Then
60: Wscript.StdOut.WriteLine "Password, minus the first letter, is found in the dictionary"
61: intPassScore = intPassScore - 1
62: End If
63:
64: ' Test four: Make sure that the password does not simply substitute 0 (zero) for the letter o (either an uppercase O or a lowercase o).
65: if instr(strPassword,"0") then
66: objRegEx.Pattern = ucase(replace(strPassword,0,"o")) & "\r\n"
67: Set colMatches = objRegEx.Execute(ucase(strAll))
68:
69: If colMatches.Count > 0 Then
70: Wscript.StdOut.WriteLine "Password is found in the dictionary after replacing zeros with ""o"""
71: intPassScore = intPassScore - 1
72: End If
73: end if
74:
75: ' Test five: Make sure that the password does not simply substitute 1 (one) for the letter l (either an uppercase L or a lowercase l).
76: if instr(strPassword,"1") then
77: objRegEx.Pattern = ucase(replace(strPassword,1,"l")) & "\r\n"
78: Set colMatches = objRegEx.Execute(ucase(strAll))
79:
80: If colMatches.Count > 0 Then
81: Wscript.StdOut.WriteLine "Password is found in the dictionary after replacing ones with ""l"""
82: intPassScore = intPassScore - 1
83: End If
84: end if
85:
86: ' Test six: Make sure that the password is at least 10 characters long but no more than 20 characters long.
87: If Len(strPassword) < 10 then
88: Wscript.StdOut.WriteLine "Password is two short"
89: intPassScore = intPassScore - 1
90: else if Len(strPassword) > 20 then
91: Wscript.StdOut.WriteLine "Password is two short"
92: intPassScore = intPassScore - 1
93: end if
94: end if
95:
96: ' Test seven: Make sure that the password includes at least one number (the digits 0 through 9).
97: objRegEx.Pattern = "\d"
98: Set colMatches = objRegEx.Execute(strPassword)
99:
100: If colMatches.Count = 0 Then
101: Wscript.StdOut.WriteLine "Password must contain at least one number (0-9)"
102: intPassScore = intPassScore - 1
103: End If
104:
105: ' Test eight: Make sure that the password includes at least one uppercase letter.
106: objRegEx.Pattern = "[A-Z]"
107: Set colMatches = objRegEx.Execute(strPassword)
108:
109: If colMatches.Count = 0 Then
110: Wscript.StdOut.WriteLine "Password must contain at least one upper case letter"
111: intPassScore = intPassScore - 1
112: End If
113:
114: ' Test nine: Make sure that the password includes at least one lowercase letter.
115: objRegEx.Pattern = "[a-z]"
116: Set colMatches = objRegEx.Execute(strPassword)
117:
118: If colMatches.Count = 0 Then
119: Wscript.StdOut.WriteLine "Password must contain at least one lower case letter"
120: intPassScore = intPassScore - 1
121: End If
122: ' Test ten: Make sure that the password includes at least one symbol.
123: objRegEx.Pattern = "[^A-Za-z0-9]"
124: Set colMatches = objRegEx.Execute(strPassword)
125:
126: If colMatches.Count = 0 Then
127: Wscript.StdOut.WriteLine "Password must contain at least one symbol"
128: intPassScore = intPassScore - 1
129: End If
130:
131: ' Test eleven: Make sure that the password does not include four (or more) lowercase letters in succession.
132: objRegEx.Pattern = "[a-z]{4,}"
133: Set colMatches = objRegEx.Execute(strPassword)
134:
135: If colMatches.Count > 0 Then
136: Wscript.StdOut.WriteLine "Password contains 4 or more lower case letters in succession"
137: intPassScore = intPassScore - 1
138: End If
139:
140: ' Test twelve: Make sure that the password does not include four (or more) uppercase letters in succession.
141: objRegEx.Pattern = "[A-Z]{4,}"
142: Set colMatches = objRegEx.Execute(strPassword)
143:
144: If colMatches.Count > 0 Then
145: Wscript.StdOut.WriteLine "Password contains 4 or more upper case letters in succession"
146: intPassScore = intPassScore - 1
147: End If
148:
149: ' Test thirteen: Make sure that the password does not include any duplicate characters.
150: objRegEx.Pattern = "(.)(.*\1)"
151: Set colMatches = objRegEx.Execute(strPassword)
152:
153: If colMatches.Count > 0 Then
154: Wscript.StdOut.WriteLine "Password contains duplicate characters"
155: intPassScore = intPassScore - 1
156: End If
157:
158: 'Final Score
159: WScript.StdOut.WriteLine
160: WScript.StdOut.Write "A password score of " & intPassScore
161: Select case intPassScore
162: case 11,12,13
163: WScript.StdOut.WriteLine " indicates a strong password."
164: case 7,8,9,10
165: WScript.StdOut.WriteLine " indicates a moderately-strong password."
166: case else
167: WScript.StdOut.WriteLine " indicates a weak password."
168: End select
Here is my submission for the Advanced Event 4 in the Microsoft Scripting Games 2008.
1: '*********************************************************************
2: ' Script Name: Event4.vbs
3: ' Version: 1.1
4: ' Author: Perry Harris (PHactotum)
5: ' Updated: 1:30 AM Friday, February 22, 2008
6: ' Purpose: Solves the 2008 winter Scripting Games Advance Event 4: Image is Everything
7: '
8: ' Usage: cscript Event4.vbs
9: ' Notes:
10: ' Keywords:
11: ' versioning: 1.0 Original release
12: ' 1.1 Modified to put lines in our calendar using + - and |
13: '*********************************************************************
14: Option Explicit
15: Dim intYear, i, intMonth
16: Dim strText
17: Dim StartDate, EndDate, CurrDate
18: Dim intLeft, intRight
19: Dim a
20:
21: 'Get the desired Month and Year for the Calendar
22: WScript.StdOut.Write "Please enter Month/Year using numeric digits: "
23: strText = WScript.StdIn.ReadLine
24:
25: 'Assuming the user used a / as the separator
26: a = split(strText,"/")
27: intMonth = a(0)
28: intYear = a(1)
29:
30: 'Start our Calendar on the first day of the given month and year
31: StartDate = DateSerial(intYear,intMonth,1)
32: EndDate = DateSerial(Year(DateAdd("m",1,StartDate)),Month(DateAdd("m",1,StartDate)),1)
33:
34: 'Write Top border
35: WScript.StdOut.Write chr(43)
36: WScript.StdOut.Write string(41,chr(45))
37: WScript.StdOut.WriteLine chr(43)
38:
39: 'Write out our Month and Year
40: WScript.StdOut.Write chr(124)
41: intLeft = (41 - Len(MonthName(intMonth) & " " & Year(StartDate))) /2
42: intRight = 41 - Len(MonthName(intMonth) & " " & Year(StartDate)) - intLeft
43: WScript.StdOut.Write space(intLeft)
44: WScript.StdOut.Write MonthName(intMonth) & " " & Year(StartDate)
45: WScript.StdOut.Write space(intRight)
46: WScript.StdOut.WriteLine chr(124)
47: WScript.StdOut.WriteLine chr(124) & space(41) & chr(124)
48:
49: 'Yes, we could have used a function for these three lines seeing as we use them repeatedly
50: WScript.StdOut.Write chr(43)
51: WScript.StdOut.Write string(41,chr(45))
52: WScript.StdOut.WriteLine chr(43)
53:
54:
55: 'Write out our days of the week tab separated and in abbreviated form
56: For i = 1 to 7
57: WScript.StdOut.Write chr(124) & space(1) & WeekDayName(i,True) & space(1)
58: next
59: WScript.StdOut.WriteLine chr(124)
60: 'And again these three lines
61: WScript.StdOut.Write chr(43)
62: WScript.StdOut.Write string(41,chr(45))
63: WScript.StdOut.WriteLine chr(43)
64:
65:
66:
67: 'Pad the first week
68: i = 0
69: While i < Weekday(StartDate) - 1
70: WScript.StdOut.Write chr(124) & space(5)
71: i = i + 1
72: wend
73:
74: 'Print The Days
75: CurrDate = StartDate
76: While CurrDate < EndDate
77: If Weekday(CurrDate) = 7 then
78: WScript.StdOut.WriteLine Chr(124) & LeftPad(Day(CurrDate),4) & space(1) & chr(124)
79: else
80: WScript.StdOut.Write chr(124) & LeftPad(day(CurrDate),4) & space(1)
81: end if
82: CurrDate = DateAdd("d",1,CurrDate)
83: Wend
84:
85: 'Pad the last week
86: If Weekday(CurrDate) > 1 then ' If we are at 1, we don't want to print a blank row
87: While Weekday(CurrDate) < 7
88: WScript.StdOut.Write chr(124) & space(5)
89: CurrDate = DateAdd("d",1,CurrDate)
90: wend
91: WScript.StdOut.WriteLine chr(124) & space(5) & chr(124)
92: end if
93:
94: 'One more time
95: WScript.StdOut.Write chr(43)
96: WScript.StdOut.Write string(41,chr(45))
97: WScript.StdOut.WriteLine chr(43)
98:
99:
100:
101: 'This is used to right justify the dates under the three letter abbreviations for the days of the week.
102: Function LeftPad(strText,intWidth)
103: LeftPad = Space(intWidth - Len(strText)) & strText
104: end function
I spent a little extra time on this one. I had a calendar that looked just like their example:
C:\scripts>cscript Event4-1.vbs Please enter Month/Year using numeric digits: 2/2008 February 2008 |
But I thought I'd like to take it up a notch. I like calendars with grid lines:
C:\scripts>cscript Event4.vbs Please enter Month/Year using numeric digits: 2/2008 +-----------------------------------------+ | February 2008 | | | +-----------------------------------------+ | Sun | Mon | Tue | Wed | Thu | Fri | Sat | +-----------------------------------------+ | | | | | | 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 | | +-----------------------------------------+ |
Here is my submission for the Advanced Event 3 in the Microsoft Scripting Games 2008.
1: '*********************************************************************
2: ' Script Name: Event3.vbs
3: ' Version: 1.0
4: ' Author: Perry Harris (PHactotum)
5: ' Updated: 9:49 PM Thursday, February 21, 2008
6: ' Purpose: Solves the 2008 winter Scripting Games Advance Event 3: Instant (Runoff) Winner
7: '
8: ' Usage: cscript Event3.vbs [phone number]
9: ' Notes:
10: ' Keywords:
11: ' versioning: 1.0 Original release
12: '*********************************************************************
13: Option Explicit
14: Dim Politicians, Losers, Candidate
15: Dim Done
16: Dim objFS, objFile
17: Dim strLine
18: Dim aVote
19: Dim i
20: Dim LowestVote
21: Dim LowestName
22: Dim TotalVotes
23:
24: Const ForReading = 1
25: 'We'll be using two Dictionaries to keep track of our Politicians and our Losers.
26: set Politicians=CreateObject("Scripting.Dictionary")
27: set Losers=CreateObject("Scripting.Dictionary")
28:
29: 'Open and read our Voting File
30: Set objFS = CreateObject("Scripting.FileSystemObject")
31: 'Just to be clear, We're not done yet
32: Done = False
33:
34: Do
35: Politicians.RemoveAll
36: TotalVotes = 0
37: Set objFile = objFS.OpenTextFile("C:\Scripts\votes.txt", ForReading)
38: Do until objFile.AtEndOfStream
39: strLine = objFile.ReadLine
40: aVote = split(strLine,",")
41: i = 0
42: Do until not(Losers.Exists(aVote(i)))
43: i = i + 1
44: loop
45:
46: If Politicians.Exists(aVote(i)) then
47: Politicians.Item(aVote(i)) = Politicians.Item(aVote(i)) + 1
48: else
49: Politicians.Add aVote(i), 1
50: end if
51: TotalVotes = TotalVotes + 1
52: Loop
53: 'Debugging statement
54: 'WScript.StdOut.WriteLine "============================="
55: 'We set LowestVote to 100%, or 1.00 so that as we find lower numbers we bubble down to the lowest result for possible extra passes.
56: LowestVote = 1
57: LowestName = "" 'Just to make sure it doesn't affect the outcome in future passes
58: For each Candidate in Politicians
59: 'The following line was used for debugging purposes
60: 'Wscript.StdOut.WriteLine Candidate & ": " & FormatPercent(Politicians.Item(Candidate)/TotalVotes,1)
61: If Politicians.Item(Candidate)/TotalVotes > 0.5 then
62: WScript.StdOut.WriteLine "The winner is " & Candidate & " with " & FormatPercent(Politicians.Item(Candidate)/TotalVotes,1) & " of the vote."
63: Done = True
64: Exit For
65: else if LowestVote > Politicians.Item(Candidate)/TotalVotes then
66: LowestName = Candidate
67: LowestVote = Politicians.Item(Candidate)/TotalVotes
68: end if
69: end if
70: next
71: Losers.Add LowestName,LowestVote 'Really don't need the vote but the Dictionary add method requires an item.
72: objFile.Close
73: Loop Until Done