#NoTrayIcon #include ;*************************************** dim $computerserial, $computerseriala dim $todaysdate, $todaysdatea, $lastdate dim $usagetimer dim $usageallowance dim $internetaccess, $internetaccessb dim $countera, $counterb dim $looper dim $internetused dim $usageinfo dim $internettimeleft dim $blockstarttime, $blockstarttimeh, $blockstarttimem dim $blockstoptime, $blockstoptimeh, $blockstoptimem dim $timenow, $timenowh, $timenowm, $timenowhs, $timenowms dim $miscdata dim $tempa, $tempb, $tempc, $tempd dim $pingresult dim $internetblocked dim $internetallowedflag dim $timenows, $timenowa, $timenowb, $timenowc Dim $Bin CHECKCONFIG () $blockstarttime = 2200 $blockstoptime = 0700 $internetaccess = 2 ;Initially block access until checked $looper = 2 $usagetimer = 1 $usageinfo = "Activating Internet Monitor. Please Wait..." ToolTip($usageinfo, 0, 0) ;GET THE DNS IP ADDRESS OF THE SYSTEM AND ADD IT TO THE REGISTRY CheckNetwork() ;BlockNetwork() ;Block unless internet allowed AllowNetwork() SYNCTIME () ;GET TODAYS DATE $todaysdatea = _NowDate() $lastdate = Regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-ld") if $lastdate <> $todaysdatea then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-du", "REG_SZ", 0) ;*************************************************************************************** ;Loop this part of the program every minuite $timenowa = 0 $timenowh = @HOUR *10000 $timenowm = @MIN *100 $timenows = @SEC $timenowa = $timenowh + $timenowm + $timenows do $internetaccess = 0 ;GET THE TIME NOW TIMENOW () ;CHECKS RE: BLOCKING INTERNET BY TIME OF DAY CHECKACCESSTIMES () ;CLOSE INTERNET ACTIVITY AS IT IS NOT THE ALLOWED TIME FOR INTERNET ACTIVITY if $internetaccess = 5 then BLOCKACCESSTIMES () ;CHECK IF INTERNET TIME EXCEEDED AS INTERNET ACCESS IS ALLOWED if $internetaccess <> 5 then ALLOWEDACCESTIMES () ACTIONINTERNETSTATUS () if $internettimeleft < 6 then TrayTip("Warning", "Your Internet Usage Will Run Out Shortly!", 5) ;Get the current time to check if a minuite as passed of internet usage $timenowb = 0 $timenowh = @HOUR *10000 $timenowm = @MIN *100 $timenows = @SEC $timenowb = $timenowh + $timenowm + $timenows $timenowc = $timenowa + 59 if $timenowa > 0 then if $timenowb > $timenowc then SYNCTIME () ;Get the time now $timenowa = 0 $timenowh = @HOUR *10000 $timenowm = @MIN *100 $timenows = @SEC $timenowa = $timenowh + $timenowm + $timenows endif endif ;ACTIONINTERNETSTATUS () LOOPCHECK () SLEEP (5000) until $looper = 10 ;*************************************************************************************** ; ============================================================================================== func CHECKCONFIG ();Get internet time and set our system Dim $MyServices Dim $MyServicesList dim $ServiceFound dim $Servicestatus Dim $objService Dim $objWMIService Dim $MyCurrentServiceState = "Stopped" $ServiceFound ="no" ;Check If the Service Exists $myServiceQuery = "Apple-Checkup" $MyServices = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $MyServicesList = $MyServices.ExecQuery("SELECT * FROM Win32_Service") If IsObj($MyServicesList) then For $MyServices in $MyServicesList If $MyServices.Name = $myServiceQuery Then $ServiceFound ="yes" $Servicestatus = $MyServices.State EndIf Next EndIf ;If Service Does Not Exist then Install & Run The Service if $ServiceFound ="no" then ; $MyService = "Apple-Checkup" $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2") $objService = $objWMIService.Get("Win32_Service.Name='" & $myServiceQuery & "'") If $objService.State = $MyCurrentServiceState Then $objService.StartService() endif endfunc ; ============================================================================================== func SYNCTIME ();Get internet time and set ouyr system ; Update the timer based on 1 minutes usage if $internetused = 1 then $usagetimer = $usagetimer + 1 RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-du", "REG_SZ", $usagetimer) $internetused = 0 endfunc ; ============================================================================================== func INCREMENTTIMER ();Get internet time and set ouyr system RunWait(@ComSpec & " /c " & "w32tm /resync", "", @SW_HIDE) endfunc ; ============================================================================================== func TIMENOW ();Get the system time and make one number for easier analysis $timenowh = @HOUR $timenowm = @MIN $timenow = ($timenowh * 100) + $timenowm endfunc ; ============================================================================================== ;CHECKS RE: BLOCKING INTERNET BY TIME OF DAY func CHECKACCESSTIMES ();Check if the internet is to be blocked due to time of day ;Read the Registry Info for start & stop times $blockstarttime = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-st") ;Read Registry Key for Usage $blockstoptime = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-ft") ;Read Registry Key for Usage ;Now Work out hours/mins for start Time $tempa = $blockstarttime / 100 $tempb = int ($tempa) ;hour $tempc = $tempb * 100 $tempd = $blockstarttime - $tempc ;mins $blockstarttimeh = $tempb $blockstarttimem = $tempd ;Now Work out Hours/mins for end time $tempa = $blockstarttime / 100 $tempb = int ($tempa) ;hour $tempc = $tempb * 100 $tempd = $blockstarttime - $tempc ;mins $blockstoptimeh = $tempb $blockstoptimem = $tempd ;Check if start block time > end block time . ;if it is then this goes past midnight so work out in 2 parts, ;> up to midnight and ;> from midnight to start time if $blockstarttime > $blockstoptime then ; this goes past midnight so deal accordingly ;Check lead-up to midnight ;check hour if $timenow > $blockstarttime Then ; It is past the beginning time to start blocking if $timenow <= 2359 Then ; It is less than the end time so start blocking $internetaccess = 5 endif EndIf if $timenow = 0 Then ; It is midnight so block $internetaccess = 5 endif ;Check from midnight till end block time if $timenow > 0 Then ; It is past the beginning time to start blocking if $timenow < $blockstoptime Then ; It is less than the end time so start blocking $internetaccess = 5 endif EndIf EndIf if $blockstarttime < $blockstoptime then ; this does not go past midnight so deal accordingly ;check hour if $timenow > $blockstarttime Then ; It is past the beginning time to start blocking if $timenow < $blockstoptime Then ; It is less than the end time so start blocking $internetaccess = 5 endif EndIf EndIf endfunc ; ============================================================================================== ;Block the internet as it is the wrong time of the day func BLOCKACCESSTIMES () $todaysdate = _NowDate() if $todaysdatea <> $todaysdate then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-du", "REG_SZ", 0) $todaysdatea = $todaysdate $usageinfo = "SORRY YOUR INTERNET IS BLOCKED: IT IS NOT THE CORRECT TIME TO ACCESS THE INTERNET" ToolTip($usageinfo, 0, 0) ; PINGCHECK () ; if $internetblocked = 1 then BlockNetwork() endfunc ; ============================================================================================== func ALLOWEDACCESTIMES ();Get internet time and set ouyr system ; $internetused = 0 ;If $internetaccess = 2 then internet activity is to be blocked ;Now Check on daily Allowance Info $todaysdate = "" $var = 0 $usagetimer = 0 $todaysdate = _NowDate() ;*************************************************************************************** ;RESET THE TIMER FOR NEW DAY if $todaysdatea <> $todaysdate then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-du", "REG_SZ", 0) $todaysdatea = $todaysdate ;*************************************************************************************** $var = 0 $usagetimer = 0 $usageallowance = 0 $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-ds") ; Read Registry key for date RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-ld", "REG_SZ", $todaysdate) $usagetimer = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-du") ;Read Registry Key for Usage SO FAR TODAY $usageallowance = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-da") ;Read Registry Key for DAILY ALLOWANCE if $usagetimer < 1 then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-du", "REG_SZ", 1) ;If date in registry does not match todays date then reset the registry if $var <> $todaysdate then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-ds", "REG_SZ", $todaysdate) RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\", "Ds-du", "REG_SZ", 0) EndIf ;Show User The Usage Allowence that is left $internettimeleft = $usageallowance - $usagetimer if $internettimeleft < 0 then $internettimeleft = 0 ;Check if usage allowence exceeds todays usage if $usageallowance < 1 then ; if usage allowence not set block access $internetaccess = 0 ; Block Internet Access endif ; if usage allowence not reached then allow access if $usageallowance - $usagetimer > 0 then ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& $internetaccess = 1 ; Allow Internet Access endif if $usageallowance - $usagetimer < 1 then $internetaccess = 2 ; Block Internet Access endif endfunc ; ============================================================================================== func ACTIONINTERNETSTATUS ();Get internet time and set our system ;$internetallowedflag = 0 $usageinfo = "Allowed Internet times: " & $blockstoptime & "hrs - " & $blockstarttime & "hrs" & @LF & "Internet Time Remaining: " & $internettimeleft & " minutes" ToolTip($usageinfo, 0, 0) ;Block or allow internet dependant on system settings if $internetaccess = 0 then $internetallowedflag = 1 PINGCHECK () if $internetblocked <> 2 then BlockNetwork() $usageinfo = "SORRY YOUR INTERNET IS BLOCKED: Your Internet Settings Are Invalid." ToolTip($usageinfo, 0, 0) endif if $internetaccess = 1 then $internetallowedflag = 1 PINGCHECK () if $internetblocked <> 1 then AllowNetwork() endif if $internetaccess = 2 then $internetallowedflag = 1 PINGCHECK () if $internetblocked <> 2 then BlockNetwork() $usageinfo = "SORRY YOUR INTERNET IS BLOCKED: YOU HAVE EXCEEDED YOUR USAGE ALLOWANCE" ToolTip($usageinfo, 0, 0) endif if $internetaccess = 5 then $internetallowedflag = 1 PINGCHECK () if $internetblocked <> 2 then BlockNetwork() $usageinfo = "SORRY YOUR INTERNET IS BLOCKED: IT IS NOT THE CORRECT TIME TO ACCESS THE INTERNET" ToolTip($usageinfo, 0, 0) endif ;if $internetallowedflag = 0 then ; $usageinfo = "Allowed Internet times: " & $blockstoptime & "hrs - " & $blockstarttime & "hrs" & @LF & "Internet Time Remaining: " & $internettimeleft & " minutes" ; ToolTip($usageinfo, 0, 0) ;endif endfunc ; ============================================================================================== func LOOPCHECK ();Get internet time and set our system ;*************************************************************************************** ;CHECK IF INTERNET SOFTWARE IS RUNNING AND LOG FOR TIMING ;Now check if Explorer is open If ProcessExists("iexplore.exe") Then If ProcessExists("iexplore.exe") Then $internetused = 1 ;set timer to plus 1 as explorer open ENDIF EndIf ;Now check if live messenger is open If ProcessExists("msnmsgr.exe") Then If ProcessExists("msnmsgr.exe") Then $internetused = 1 ;set timer to plus 1 as explorer open ENDIF EndIf ;Now check if firefox is open If ProcessExists("firefox.exe") Then If ProcessExists("firefox.exe") Then $internetused = 1 ;set timer to plus 1 as explorer open ENDIF EndIf ;Now check if AOL is open If ProcessExists("waol.exe") Then If ProcessExists("waol.exe") Then $internetused = 1 ;set timer to plus 1 as explorer open ENDIF EndIf ;*************************************************************************************** endfunc ; ============================================================================================== func PINGCHECK () $pingresult = Ping("www.google.com",250) If $pingresult Then ;Internet Not Blocked $internetblocked = 1 Else ;Internet Access Blocked $internetblocked = 2 EndIf EndFunc ; ============================================================================================== Func AllowNetwork() local $connectionname local $IPAddress local $commandline local $pingresult dim $iFlag = 1 dim $OSver ; local $internetblocked ;Get DNS info From Registry $connectionname = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\DIGITECH\", "DefaultNetworkName") $IPAddress = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\DIGITECH\", "DefaultIP") ;Now Un-Block the Internet $commandline = "cmd /c netsh interface ip set dns """ & $connectionname & """ static " & $IPAddress & " primary" Run($commandline, "", @SW_HIDE ) sleep (2000) $pingresult = Ping("www.google.com",250) If $pingresult Then ;Internet Not Blocked $internetblocked = 1 Else ;Internet Access Blocked $internetblocked = 2 EndIf ; Disble the NIC to activate the new settings ; ============================================================================================== ; Read from the .ini-File which network connection to use ; $s_interface = "Local Area Connection" $arrNetCons = _GetNetConNames(_NetConsFolderObject()) ; Disable the NIC If $OSver <> "WIN_2000" And $OSver <> "WIN_XP" And $OSver <> "WIN_2003" Then $strNetCon = $arrNetCons[0] ; NetCon on Vista/W2K8 _NicToggleNEW($strNetCon, $iFlag) Else $strNetCon = $arrNetCons[3] ; NetCon on Windows _NicToggleOLD($strNetCon, $iFlag) EndIf Return $internetblocked EndFunc ; ============================================================================================== Func BlockNetwork() local $connectionname local $IPAddress local $commandline local $pingresult dim $iFlag = 0 dim $OSver ;Get DNS info From Registry $connectionname = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\DIGITECH\", "DefaultNetworkName") $IPAddress = "10.10.10.1" ;Now Un-Block the Internet $commandline = "cmd /c netsh interface ip set dns """ & $connectionname & """ static " & $IPAddress & " primary" Run($commandline, "", @SW_HIDE) sleep (2000) $pingresult = Ping("www.GOOGLE.com",250) If $pingresult Then ;Internet Not Blocked $internetblocked = 1 Else ;Internet Access Blocked $internetblocked = 2 EndIf ; Disble the NIC to activate the new settings ; ============================================================================================== ; Read from the .ini-File which network connection to use ; $s_interface = "Local Area Connection" $arrNetCons = _GetNetConNames(_NetConsFolderObject()) ; Disable the NIC If $OSver <> "WIN_2000" And $OSver <> "WIN_XP" And $OSver <> "WIN_2003" Then $strNetCon = $arrNetCons[0] ; NetCon on Vista/W2K8 _NicToggleNEW($strNetCon, $iFlag) Else $strNetCon = $arrNetCons[3] ; NetCon on Windows _NicToggleOLD($strNetCon, $iFlag) EndIf Return $internetblocked EndFunc ; ============================================================================================== Func CheckNetwork ();($IPAddress, $connectionname) local $result Local $substring Local $line Local $file Local $choppedstring ; Local $connectionname ; Local $IPAddress Local $len local $commandline FileRecycle("c:\digitech-secure\ipconfig.txt") sleep(2000) ;READ THE REQUIRED NETWORK INFO RunWait('cmd /c ipconfig > c:\digitech-secure\ipconfig.txt', "", @SW_HIDE) ;NOW READ THE CONTENTS TO FIND REQIRED DATA $file = FileOpen("c:\digitech-secure\ipconfig.txt", 0) ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ;Check for Connection Name $substring = "Ethernet adapter " $result = 0 $result = StringInStr($line, $substring) ;We have a matching string so get the data we require if $result = 1 Then $choppedstring = StringTrimLeft($line, 17) ;remove the left part of the line $connectionname = StringTrimright($choppedstring, 1) ;remove the left part of the line ; MsgBox(0, $line, $choppedstring) endif ;Check for IP address $substring = "Default Gateway ." $result = 0 $result = StringInStr($line, $substring) ;We have a matching string so get the data we require if $result > 1 Then ;Get the end of the string $substring = ": " $result = StringInStr($line, $substring) $choppedstring = StringTrimLeft($line, $result) ;remove the left part of the line $choppedstring = StringStripWS($choppedstring, 8) ;Remove all whitespace $IPAddress = StringTrimright($choppedstring, 0) ;remove the left part of the line ; MsgBox(0, $line, $IPAddress) endif Wend FileClose($file) ;SAVE THE INFO TO THE REGISTRY IF IT IS LEGITIMATE $len = StringLen($IPAddress) if $len > 6 then if $IPAddress <> "10.10.10.1" then ;Check the value is not our loopback address RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\DIGITECH\", "DefaultIP", "REG_SZ", $IPAddress) endif endif $len = StringLen($connectionname) if $len > 0 then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\DIGITECH\", "DefaultNetworkName", "REG_SZ", $connectionname) endif ;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{79CA3BD3-B8C5-45A3-AB73-5BF3EEFDBB93} NameServer - contains dcp address return $IPAddress return $connectionname EndFunc ; Function _NetConsFolderObject to find the folder containing the network connection objects ; ============================================================================================== Func _NetConsFolderObject() dim $OSver If $OSver <> "WIN_2000" And $OSver <> "WIN_XP" And $OSver <> "WIN_2003" Then Local $wbemFlagReturnImmediately = 0x10 Local $wbemFlagForwardOnly = 0x20 Local $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colNetwork = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Else $objShell = ObjCreate("Shell.Application") $strNetConn = "Network Connections" $objCP = $objShell.Namespace(3) For $clsConn In $objCP.Items If $clsConn.Name = $strNetConn Then $colNetwork = $clsConn.GetFolder EndIf Next EndIf Return $colNetwork EndFunc ;==>_NetConsFolderObject ; Function _GetNetConNames to find the network connection objects ; ============================================================================================== Func _GetNetConNames($colNetwork) Dim $strNetworks dim $OSver If $OSver <> "WIN_2000" And $OSver <> "WIN_XP" And $OSver <> "WIN_2003" Then If IsObj($colNetwork) Then For $clsConn In $colNetwork If $clsConn.NetConnectionID <> '' Then $strNetworks &= $clsConn.NetConnectionID & '|' Next Else MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_NetworkAdapter") EndIf Else For $clsConn In $colNetwork.Items If StringInStr($clsConn.Name, "Wizard") = 0 Then $strNetworks = $strNetworks & $clsConn.Name & "|" EndIf Next EndIf $strNetworks = StringLeft($strNetworks, StringLen($strNetworks) - 1) $arrNetworks = StringSplit($strNetworks, "|") ; _ArrayDelete($arrNetworks, 0) ; _ArraySort($arrNetworks) Return $arrNetworks EndFunc ;==>GetNetworkNames ; Function _NicToggleNEW to Disable and Enable a Network card using 'Shell.Application' - Parameters: $oLanConnection and $iFlag ; ============================================================================================== Func _NicToggleNEW($strNetworks, $iFlag) dim $colNetwork _NetConsFolderObject() If IsObj($colNetwork) Then For $clsConn In $colNetwork If $clsConn.NetConnectionID = $strNetworks Then If $iFlag = 0 And $clsConn.NetEnabled = True Then $clsConn.Disable ElseIf $iFlag = 1 And $clsConn.NetEnabled = False Then $clsConn.Enable EndIf ExitLoop EndIf Next Else MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_NetworkAdapter") EndIf EndFunc ;==>_NicToggleNEW ; Function _NicToggleOLD to Disable and Enable a Network card using 'Shell.Application' - Parameters: $oLanConnection and $iFlag ; ============================================================================================== Func _NicToggleOLD($strNetworks, $iFlag) dim $colNetwork dim $strDisable dim $strEnable For $clsConn In $colNetwork.Items If $clsConn.Name = $strNetworks Then For $clsVerb In $clsConn.verbs If $iFlag = 0 And $clsVerb.name = $strDisable Then $clsVerb.DoIt Sleep(200) Return 0 EndIf If $iFlag = 1 And $clsVerb.name = $strEnable Then $clsVerb.DoIt Sleep(200) Return 1 EndIf Next EndIf Next EndFunc ;==>_NicToggleOLD