Restricting PC access/usage at certain times?

csm

csm

Associate
Joined
17 Feb 2008
Posts
90
Is this possible?

The old dear has asked me to try implement some sort of time-based restriction to one of the home computers.

Please help!
 
logon script that checks the time and shuts off if it's outside the allowed hours. Simple and easy to do, but can be circumvented by safe mode.

Edit: Hmmm, do you mean no access to the computer or no access to the internet? If the latter, I wrote a script a while back that does that I think. If you want, I'll dig it out and post it.
 
OS: XP

Ideally to the computer (unless an admin)
Though I guess just an internet based restriction may work as that is the primary use.
 
This code should check the time of day and if it's outside allotted hours, disable internet (it simply disables the network connection) and enables it inside allotted hours. You'll need to run it at startup; also you'll want to change the allotted hours and change the network connection name to whatever yours is called.

Const ssfCONTROLS = 3

'This is the name of the network connection
sConnectionName = "Wireless Network Connection"

sEnableVerb = "En&able"
sDisableVerb = "Disa&ble"

'Enter start time in seconds (86400 seconds in a day)
startTime = 32400
endTime = 61200

set shellApp = createobject("shell.Application")
set oControlPanel = shellApp.Namespace(ssfCONTROLS)

Set oNetConnections = Nothing
For Each folderitem in oControlPanel.Items
If folderitem.Name = "Network Connections" then
set oNetConnections = folderitem.getfolder: Exit For
End if
Next

If oNetConnections is Nothing then
msgBox "Couldn't find 'Network Connections' folder",0,"Error"
wscript.Quit
End if

Set oLanConnection = Nothing
For Each folderitem in oNetConnections.items
If lcase(folderitem.Name) = lcase(sConnectionName) then
Set oLanConnection = folderitem: Exit For
End if
Next

If oLanConnection is Nothing then
msgBox "Couldn't find '" & sConnectionName & "' item",0,"Error"
wscript.Quit
End if

bEnabled = True
Set oEnableVerb = nothing
Set oDisableVerb = nothing
For Each Verb in oLanConnection.verbs
If verb.name = sEnableVerb then
Set oEnableVerb = verb
bEnabled = False
Exit For
ElseIf verb.name = sDisableVerb then
set oDisableVerb = verb
bEnabled = True
Exit For
End if
Next

If bEnabled = False then
oEnableVerb.DoIt
wscript.Sleep 5000
End if

wscript.Sleep 1000

l = 1
Do Until l = 0
Do Until timer < startTime Or timer > endTime
'adjust sleep time as needed; in reality anything above 1ms is going to have little impact on performance
wscript.Sleep 10000
Loop

Set oNetConnections = Nothing
For Each folderitem in oControlPanel.Items
If folderitem.Name = "Network Connections" then
set oNetConnections = folderitem.getfolder: Exit For
End if
Next

If oNetConnections is Nothing then
msgBox "Couldn't find 'Network Connections' folder",0,"Error"
wscript.Quit
End if

Set oLanConnection = Nothing
For Each folderitem in oNetConnections.items
If lcase(folderitem.Name) = lcase(sConnectionName) then
Set oLanConnection = folderitem: Exit For
End if
Next

If oLanConnection is Nothing then
msgBox "Couldn't find '" & sConnectionName & "' item",0,"Error"
wscript.Quit
End if

bEnabled = True
Set oEnableVerb = nothing
Set oDisableVerb = nothing
For Each Verb in oLanConnection.verbs
If verb.name = sEnableVerb then
Set oEnableVerb = verb
bEnabled = False
Exit For
ElseIf verb.name = sDisableVerb then
set oDisableVerb = verb
bEnabled = True
Exit For
End if
Next

If bEnabled = True then
oDisableVerb.DoIt
wscript.Sleep 5000
End if

wscript.Sleep 1000
Do Until timer > startTime And timer < endTime
'adjust sleep time as needed; in reality anything above 1ms is going to have little impact on performance
wscript.Sleep 10000
Loop

Set oNetConnections = Nothing
For Each folderitem in oControlPanel.Items
If folderitem.Name = "Network Connections" then
set oNetConnections = folderitem.getfolder: Exit For
End if
Next

If oNetConnections is Nothing then
msgBox "Couldn't find 'Network Connections' folder",0,"Error"
wscript.Quit
End if

Set oLanConnection = Nothing
For Each folderitem in oNetConnections.items
If lcase(folderitem.Name) = lcase(sConnectionName) then
Set oLanConnection = folderitem: Exit For
End if
Next

If oLanConnection is Nothing then
msgBox "Couldn't find '" & sConnectionName & "' item",0,"Error"
wscript.Quit
End if

bEnabled = True
Set oEnableVerb = nothing
Set oDisableVerb = nothing
For Each Verb in oLanConnection.verbs
If verb.name = sEnableVerb then
Set oEnableVerb = verb
bEnabled = False
Exit For
ElseIf verb.name = sDisableVerb then
set oDisableVerb = verb
bEnabled = True
Exit For
End if
Next

If bEnabled = False then
oEnableVerb.DoIt
wscript.Sleep 5000
End if

wscript.Sleep 1000
Loop

There's probably an easier way of doing it but this worked for me when I was using XP, I've tweaked it a bit to do what you want. It doesn't work on Vista or 7 though so I haven't been able to properly error-check it. Use at your risk :p but it should be fine. Once you know it's working, add a line at the top saying On Error Resume Next, that keeps it going unless you terminate wscript.exe in Task Manager. You'll want to put it in the startup folder.

Edit: currently set to allow internet 9-5.
 
Back
Top Bottom