Here is a little script I wrote this weekend out of frustration while trying to get my son to learn his multiplication tables. I had a little fun with it so thought it may be worth sharing, I'm sure someone can greatly improve it!
' Logon script to help your child learn their multiplication tables!! ' ' If your kid is like mine he loves to play Internet games but doesn't ' love math so I created this logon script in an attempt to encourage ' him to do some multiplication / division work before he logs on ' to the computer. You definitely should not have your kid running ' with an Administrator account or this plan will fail miserably and ' your child may just have you solving math problems instead of him. ' This script has no way of preventing someone from using a ' calculator to get answers but you can configure the script to ' run as many math problems as you want before logon is granted. ' ' 1. Run gpedit.msc to launch the Local Group Policy Editor. ' Drill down to User Configuration --> Windows Settings --> ' Scripts (Logon/Logoff) and then double-click Logon to see ' any Logon scripts configured for local computer. ' (there should not be any listed in a workgroup environment) ' From the Scripts tab click the Add button and click Browse to ' open the %Windir%\System32\GroupPolicy\User\Scripts\Logon ' directory. ' ' 2. Save this script to that folder with a .vbs file extension, ' for example save as "mathtables.vbs". Then select the script ' and click the Open button to populate the Script Name: text ' box. Make a note of the folder that you've saved this script ' to because you'll need to make a couple of changes to ' the script and save it again before it is ready to run. ' ' 3. Under Script parameters enter //I (for interactive), click ' OK, and click OK again to close the Logon Properties dialog box. ' ' 4. Set wscript.exe as the default scripting engine ' by running the following from a command prompt: ' ' cscript //h:wscript //s ' ' See http://support.microsoft.com/kb/245254 for details, ' this article applies to Windows Server 2000 but works ' fine with Windows 7 too. ' ' Note that you should set the default scripting engine to ' wscript.exe because when cscript.exe is the default scripting ' engine it displays a command prompt when it is called ' (hence the name Cscript.exe). When the cscript.exe command ' prompt is closed the associated script is dismissed. The ease ' with which such a script can be dismissed may present an ' irresistible option for bypassing the script if your child is ' in a hurry to logon and can easily bypass your best efforts ' to help them learn their math tables! ' ' When wscript.exe calls a script there is no visible command ' prompt displayed that can be closed to bypass the logon script ' so easily. Although undoubtedly there are numerous other ' ways to bypass this logon script at least you can remove ' the almost laughable notion of trying to enforce a logon script ' that can be "defeated" with just a single mouse click! :>) ' ' 5. While you've got the Local Group Policy Editor open drill ' down to User Configuration --> Administrative Templates --> ' System --> Scripts. Then enable Run logon scripts synchronously ' to ensure that the script will be processed before the desktop is ' displayed. Also enable Run logon scripts visible. I'm ' not positive if this option must be enabled but, it did not ' cause any problems. ' ' Note This script was only tested on a non-domain machine ' so YMMV if you've set up a home domain or such. ' ' 6. Close the Local Group Policy Editor. ' ' 7. Edit the script as appropriate and save changes. set objNetwork = createobject("wscript.network") ' Change "bill" to your child's username so that ' the script only executes when the specified ' user logs on to Windows. ' Change "bill" to your child's user accountIf lcase(objNetwork.Username) = "bill" Then Mathtables()Else Wscript.QuitEnd If Sub Mathtables()On Error Resume Next ' The Next_2() function of the System.Random object' seems to provide a more consistently random set of' numbers than does the VBScript Rnd function, which ' will often generate the same "random" number over' and over. Set objRandom = CreateObject("System.Random") ' First number is lower end of range, second number is upper end of range - 1. ' In this case the first factor will be a random number from 1 - 12 inclusive. factor1 = objRandom.Next_2(1, 13) ' Set number of math questions to ask here. numquestions = 10 For i = 1 to numquestions ' In this case the second factor will be a random number from 1 - 12 inclusive. factor2 = objRandom.Next_2(1, 13) product = factor1 * factor2 ' generate a random number to switch factors or ' switch between multiplication and division problems. multordiv = objRandom.Next_2(1,4) Select Case multordiv Case 1 temp = InputBox("What is " & factor1 & " x " & factor2 & "?", "Multiply by " & factor1 & "s, " & i & " of " & numquestions & " questions.") If Int(temp) = product Then If err.number <> 0 Then MsgBox "Non-numeric value or no value entered." & vbcrlf & vbcrlf & "Incorrect answer.",,"Incorrect Answer" Exit For End If If i = numquestions Then MsgBox factor1 & " x " & factor2 & " = " & product & "!" & vbcrlf & vbcrlf & i & " out of " & i & " correct!",,"Done!" Else MsgBox factor1 & " x " & factor2 & " = " & product & "!" & vbcrlf & vbcrlf & i & " down, " & numquestions - i & " to go.",,"Correct!" End If Else MsgBox factor1 & " x " & factor2 & " does not equal " & temp & vbcrlf & vbcrlf & factor1 & " x " & factor2 & " = " & product,,"Incorrect" Exit For End if Case 2 temp = InputBox("What is "& factor2 & " x " & factor1 & "?","Multiply by " & factor1 & "s, " & i & " of " & numquestions & " questions.") If Int(temp) = product Then If err.number <> 0 Then MsgBox "Non-numeric value or no value entered." & vbcrlf & vbcrlf & "Incorrect answer.",,"Incorrect Answer" Exit For End If If i = numquestions Then MsgBox factor2 & " x " & factor1 & " = " & product & "!" & vbcrlf & vbcrlf & i & " out of " & i & " correct!",,"Done!" Else MsgBox factor2 & " x " & factor1 & " = " & product & "!" & vbcrlf & vbcrlf & i & " down, " & numquestions - i & " to go.",,"Correct!" End If Else MsgBox factor2 & " x " & factor1 & " does not equal " & temp & vbcrlf & vbcrlf & factor2 & " x " & factor1 & " = " & product,,"Incorrect Answer" Exit For End if Case Else temp = InputBox("What is "& product & " / " & factor1 & "?","Divide by " & factor1 & "s, " & i & " of " & numquestions & " questions.") If Int(temp) = factor2 Then If err.number <> 0 Then MsgBox "Non-numeric value or no value entered." & vbcrlf & vbcrlf & "Incorrect answer.",,"Incorrect Answer" Exit For End If If i = numquestions Then MsgBox product & " / " & factor1 & " = " & factor2 & "!" & vbcrlf & vbcrlf & i & " out of " & i & " answered correctly!",,"Done!" Else MsgBox product & " / " & factor1 & " = " & factor2 & "!" & vbcrlf & vbcrlf & i & " down, " & numquestions - i & " to go.",,"Correct!" End If Else MsgBox product & " / " & factor1 & " does not equal " & temp & vbcrlf & vbcrlf & product & " / " & factor1 & " = " & factor2,,"Incorrect" Exit For End If End Select Next If Err.number = 0 Then If i = numquestions + 1 Then MsgBox "You answered " & i -1 & " out of " & i -1 & " correctly, test completed!",,"Success!" Else MsgBox "You answered " & i - 1 & " out of " & numquestions & " correctly. " & vbcrlf & vbcrlf & "You need to answer all " & numquestions & " correctly." & vbcrlf & vbcrlf & "Test not completed successfully.",,"Test Failed" Logoff() End If Else MsgBox "Error occurred, incorrect answer." & vbcrlf & "Please try again later.","Incorrect Answer" Logoff() End If End Sub ' Logoff() sub logs off the current user session. Sub Logoff() Dim Connection, WQL, SystemClass, System ' Get connection To local wmi. Set Connection = GetObject("winmgmts:root\cimv2") ' Get Win32_OperatingSystem objects - only one object In the collection. WQL = "Select Name From Win32_OperatingSystem" Set SystemClass = Connection.ExecQuery(WQL) ' comment out the following line when ready to implement logoff functionality. MsgBox "You did not correctly answer all questions, logging off now.",,"Logging Off" ' uncomment the next three lines to implement logoff functionality. ' For Each System In SystemClass ' System.Win32ShutDown (0 + 4) ' Next End Sub
Carsten Siemens edited Revision 14. Comment: fixed typo
I like it =). Very clever.