AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Timer COMPLICATION
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
sosaited



Joined: 24 Feb 2005
Posts: 233

PostPosted: Fri Apr 29, 2005 12:51 pm    Post subject: Timer COMPLICATION Reply with quote

hi everyone...
i needed to make a script that could DISALLOW the "users" to operate computer more than 10 Minutes each day until a specific day.so after thinking alot i made a "freaky style" script... but am having some problem... THis part checks constantly for any CHANGES in the time (minutes)... and if it sees any .. it reverses the settings back to last SAVED:

Code:
...............
SetTimer, MinCheck, 2000
.......

MinCheck:
v_Hour_2 =
v_Min_2 =
v_Sec_2 =
v_Min_2changed =
v_Hour_2 = %A_Hour%
v_Min_2 = %A_Min%
v_Sec_2 = %A_Sec%
v_Min_2changed := (v_Min_2 + 01)
If A_Sec between 00 and 58
   Loop
   {
      If v_Min_2 <> %A_Min%
         {
         v_Hour_backup2 =
         v_Min_backup2 =
         v_Sec_backup2 =
         v_Hour_backup2 = %A_Hour%
         v_Min_backup2 = %A_Min%
         v_Sec_backup2 = %A_Sec%
         SetTimer, MinCheck, Off
         Run, %comspec%
         WinWait, ahk_class ConsoleWindowClass
         Send, time{Enter}
         Send, %v_Hour_2%:%v_Min_2changed%:%v_Sec_2%.00{Enter}
         WinClose, ahk_class ConsoleWindowClass
         TrayTip, An External Attempt was made to change the TIME (Minute)`,  So Stop Messing with me and go to study 'cause you AINT gonna win. -> Time changed FROM "%v_Hour_backup2%:%v_Min_backup2%:%v_Sec_backup2%" TO "%v_Hour_2%:%v_Min_2changed%:%v_Sec_2%", 5, 3
         SetTimer, MinCheck, On
         Break
         }
   }
return


The problem is that with a TIMER setting of (1000 ms) the script detects changes in time... but *sometimes* it changes the time back when the next minute is about to come (at 59 seconds) and if i change the TIMER setting to (2000 ms) it doesnt detect or do anything at all... so suggestions needed please...and sorry for any Inconvenience

Happy Scripting
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Fri Apr 29, 2005 4:02 pm    Post subject: Reply with quote

Have you thought about the following approach?
- Start the script when the PC boots
- Save the time A_Now
- Check periodically (once a second) if the saved time + A_TickCount agrees with the date/time setting of the computer (within one second). If not, set the time back to what it has to be, and give the warning. This way you can trust the PC time. And using TickCount avoids the problem when the minute value wraps.

You will have problems at daylight saving changes and when the user really needs to adjust time. From the task list you could kill the script and make the changes. Hopefully, normal users won't know how to kill a task. Otherwise, you cannot do anything.
Back to top
View user's profile Send private message
sosaited



Joined: 24 Feb 2005
Posts: 233

PostPosted: Fri Apr 29, 2005 5:27 pm    Post subject: Reply with quote

thanks Laszlo
i tried your approach.. but it doesnt work... maybe cause the A_TickCount is in float... and when i change it to seconds by dividing it to 1000 ...it always gives decimal places with it... and when compared with A_Now its always different...and let me tell you whole of my script... its purpose is to Stop every User (Every USER including ME) to use the Computer for more than 10 minutes a day ... and when June 8th comes.. this script must disable itsefl .,. and remove itself from registry/startup (computer back to normal)... now i know it sounds crazy to make a script that can DISALLOW/Stop everyone INCLUDING ITS PROGRAMMER to Alter its state by ANY MEANS (the 10 minute period is SPECIFIC from 1:05 to 1:15).. so to do that i made the script with these capabilities:
- After it will be complete... Once its RUN . It will Add itself to Startup
- It will Close INSTANTLY any windows that MUST BE USED to KILL IT (System Configuration, Task Manager etc)
- If it detects any change in Hour/Date/Month settings of the pc ... it reverts them (and those parts are working fine except for the MINUTE one)
- Every it exists.. it saves ALL TIME INFO (date, month, hour, TIME COMPUTER WAS USED) to a TXT file and then it COMPILES itself alongwith the FILE
- (In Case of if someone changed the date to June 8th i added this: )every time the window runs again it opens its EXE file (Obviously cause it is run through that exe) and extracts the TXT file and see's the Difference between the previous Date and todays date and if the difference is more than one DAY it sets the date back to previous(the computer is supposed to run everyday)
- and some more things and info... which i am leaving..
so U must be annoyed right now... but i am like that .. so Really sorry about that... anyways... so can you tell me how to Fix the Minute Problem PLEASE (And if you can give any other tips TOO)..sorry again Buddy for disturbing too much Sad
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Fri Apr 29, 2005 6:08 pm    Post subject: Reply with quote

You can use Transform Round to make the result integer:
Code:
a := 123/10
MsgBox %a%
Transform b, Round, a
MsgBox %b%
It seems to be very difficult to make your restrictions bullet proof. The user can boot to safe mode or to the recovery console and removes the program from the AutoStart folder, or even from the registry. He can install a second copy of the OS, boot from a CD or floppy, etc. If you post your final script (without the confidential part), we can try to break it. I think it is instructional, we can learn something about tamper resistant SW and might develop tools in AHK for writing it.
Back to top
View user's profile Send private message
sosaited



Joined: 24 Feb 2005
Posts: 233

PostPosted: Fri Apr 29, 2005 7:41 pm    Post subject: Reply with quote

Quote:
You can use Transform Round to make the result integer:Code:
a := 123/10
MsgBox %a%
Transform b, Round, a
MsgBox %b%


I tried it (i've modified itofcourse.. you can see it in in my script). but it starts to show the msgbox after some time (sometimes after 10 seconds or so) and i think its cause when the Transform Rounds it to the WRONG digit(not mathematically ..but according to our scripts' need)... so i think you'll have to tell me something else (maybe something with my idea cause i really considered everything else when making this script:)) and about the script ... well here it is (as it is on my pc At the moment) nothing is confidential Smile... and you'll notice that it is incomplete (cause i wanted to fix the minute thingi first) so if you can ADD something in it or tips... PLEASE tell me THANKS **You'll HAVe to Read and with Full concentration (cause its all messed up and its a bit complicated) (PLEASE NOTE THAT I AM NOT "THAT" EXPERT IN AHK AT The Moment so this script be a bit different according to what i could think)

Code:
; The First line in the info file is DATE
;Second is Month
;Third is Minute
;Fourth is Hour

#Persistent
SetBatchLines, -1
IfNotExist, C:\Windows\Info.txt, FileAppend, %A_DD%`n%A_MM%`n%A_Min%`n%A_Hour%, C:\Windows\Info.txt
FileInstall, C:\Windows\Info.txt, C:\Windows\Info.txt
v_nowi = %A_Now%
v_ticki := A_TickCount/1000
Transform, v_tickii, Round, v_ticki
Menu, Tray, NoStandard
Menu, Tray, Add, INFO, Info
Menu, Tray, Add, Exit, Exit


SetWinDelay, -1
SetTimer, Info, 50000
SetTimer, CloseWindows, 10
SetTimer, HourCheck, 8000
SetTimer, MinCheck, 1000
;SetTimer, Block, 2000


return



CloseWindows:
WinClose, System Configuration Utility
WinClose, Windows Task Manager
return

HourCheck:
v_Hour_1 =
v_Min_1 =
v_Min_1changed =
v_Hour_1 = %A_Hour%
v_Min_1 = %A_Min%
v_Min_1changed := (v_Min_1 + 01)

If A_Min between 00 and 58
   Loop
   {
      If v_Hour_1 <> %A_Hour%
         {
         v_Hour_backup1 =
         v_Min_backup1 =
         v_Sec_backup1 =
         v_Hour_backup1 = %A_Hour%
         v_Min_backup1 = %A_Min%
         v_Sec_backup1 = %A_Sec%
         SetTimer, HourCheck, Off
         Run, %comspec%
         WinWait, ahk_class ConsoleWindowClass
         Send, time{Enter}
         Send, %v_Hour_1%:%v_Min_1changed%:00.00{Enter}
         WinClose, ahk_class ConsoleWindowClass
         TrayTip,  (ABFAST), An External Attempt was made to change the TIME (Hour)`, ....... -> Time changed FROM "%v_Hour_backup1%:%v_Min_backup1%:%v_Sec_backup1%" to "%v_Hour_1%:%v_Min_1changed%:00.00", 5, 3
         SetTimer, HourCheck, On
         Break
         }
   }

return
/*
MinCheck:
v_Hour_2 =
v_Min_2 =
v_Sec_2 =
v_Min_2changed =
v_Hour_2 = %A_Hour%
v_Min_2 = %A_Min%
v_Sec_2 = %A_Sec%
v_Min_2changed := (v_Min_2 + 01)
If A_Sec between 00 and 58
   Loop
   {
      If v_Min_2 <> %A_Min%
         {
         v_Hour_backup2 =
         v_Min_backup2 =
         v_Sec_backup2 =
         v_Hour_backup2 = %A_Hour%
         v_Min_backup2 = %A_Min%
         v_Sec_backup2 = %A_Sec%
         SetTimer, MinCheck, Off
         Run, %comspec%
         WinWait, ahk_class ConsoleWindowClass
         Send, time{Enter}
         Send, %v_Hour_2%:%v_Min_2changed%:%v_Sec_2%.00{Enter}
         WinClose, ahk_class ConsoleWindowClass
         TrayTip, (ABFAST), An External Attempt was made to change the TIME (Minute)`, , ......... -> Time changed FROM "%v_Hour_backup2%:%v_Min_backup2%:%v_Sec_backup2%" TO "%v_Hour_2%:%v_Min_2changed%:%v_Sec_2%", 5, 3
         SetTimer, MinCheck, On
         Break
         }
   }
return
*/
MinCheck: ; LASZLO........
v_tickf := (A_TickCount/1000) - v_tickii
Transform, v_tickff, Round, v_tickf
v_check := v_nowi + v_tickff
If v_check <> %A_Now%
   MsgBox, not

return

Info:
TrayTip, (ABFAST), This Is A Program That Disallows Use of this computer more than 10 minutes a day until June 8th`, 2005, 3, 1
return

Exit:
ExitApp
return

Block:
If A_Hour <> 01 ; THE ALLOWED TIME IS FROM 01:05 TO 01:15
   {
   Sleep, 5000
   BlockInput, On
   TrayTip,  you are not allowed to use the computer at this time`, -> Shutting Down MAINFRAME..., 10, 2
   v_error_Date = %A_DD%
   v_error_Month = %A_MM%
   v_error_Min = %A_Min%
   v_error_Hour = %A_Hour%
   TrayTip, (ABFAST), Saving Illegal Session Time/Date info..., 1, 1
   FileDelete, C:\Windows\Info.txt
   FileAppend, %v_error_Date%`n%v_error_Month%`n%v_error_Min%`n%v_error_Hour%, C:\Windows\Info.txt
   TrayTip, ABFAST, Saving info file alongwith Core File.., 1, 1
   SetKeyDelay, -1
   IfExist, C:\Windows\abfast.exe
      FileDelete, C:\Windows\abfast.exe
   Run, %comspec%
   WinWait, ahk_class ConsoleWindowClass
   Send, U:\Downloaded\Softwares\Softwares\AutoHotkey103105\Compiler\Ahk2Exe.exe /in C:\Windows\abfast.ahk /out C:\Windows\abfast.exe /icon "C:\Program Files\Creative\SBAudigy\Audigy.ico"
   Send, {Enter}
   Send, cd..{Enter}cd..{Enter}c:{Enter}
   Send, {Enter 25}
   Sleep, 3000
   WinClose, ahk_class ConsoleWindowClass
   TrayTip, ABFAST, Shutting Down..., 1, 1
   Run, C:\Windows\sd.exe ; THIS IS ANOTHER SCRIPT TO SHUT DOWN
   ExitApp
   }
return

Read:
FileReadLine, v_read_1, C:\Windows\Info.txt, 1
FileReadLine, v_read_2, C:\Windows\Info.txt, 2
FileReadLine, v_read_3, C:\Windows\Info.txt, 3
FileReadLine, v_read_4, C:\Windows\Info.txt, 4
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Sat Apr 30, 2005 1:17 am    Post subject: Reply with quote

Let's fix the time-check routine first. Because of the freaking Greek, we have base 60 and 24 number systems with time (sec, min; hour), so we cannot just add a number to a time value, but have to check if it became larger than allowed, and propagate a carry if it did. What I meant in my previous post is described in the following script.
Code:
#persistent
Tick0 = %A_TickCount%
Day0  = %A_YDay%
Hour0 = %A_Hour%     ; Initial PC time
Min0  = %A_Min%
Sec0  = %A_Sec%

SetTimer TimeCheck, 1000
return

TimeCheck:
   Transform, SecD, Floor, (A_TickCount-Tick0)/1000
   Day  = %A_YDay%
   Hour = %A_Hour%   ; Snapshot of PC time
   Min  = %A_Min%
   Sec  = %A_Sec%

   Sec1 := ModDiv(Sec0+SecD,  carry,60)
   Min1 := ModDiv(Min0+carry, carry,60)
   Hour1:= ModDiv(Hour0+carry,carry,24)
   Day1 := Day0 + carry

   Sec2 := ModDiv(Sec0+SecD+1,carry,60)
   Min2 := ModDiv(Min0+carry, carry,60)
   Hour2:= ModDiv(Hour0+carry,carry,24)
   Day2 := Day1 + carry

   if (Sec1=Sec && Min1=Min && Hour1=Hour && Day1=Day && A_Year=2005)
      Return
   if (Sec2=Sec && Min2=Min && Hour2=Hour && Day2=Day && A_Year=2005)
      Return
   MsgBox PC time has been changed!
return

ModDiv(z, ByRef carry, m)
{
   Transform x, Mod, %z%, %m%
   carry := z - x
   carry /= m     ; Integer division
   Return x
}
return
Because we don't know if the tick counter is updated first or the time/date variables, there can be a 1 sec offset, without touching the PC time settings. Therefore, we have to calculate 2 current time values with the tick counter, and a match with any of them validates the PC timer. (In theory it is possible that we have to calculate a third set of time/date values, too, with subtracting 1 sec from the tick difference. I tested the script for a few minutes in my PC and it did not seem to be necessary.)
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Sat Apr 30, 2005 2:35 am    Post subject: Reply with quote

The next problem is using third party utilities, like Startup Inspector for Windows. It can prevent loading any program started from the Startup folder or from the registry. We have to add another timer routine, which checks periodically if the startup entry has been removed, and add it back.

Other type of utilities, like Sysinternals' Process Explorer, can kill any process, including AHK. Closing the Windows Task Manger from the script works surprisingly well. (I was not able to change or remove the title of its window and so I could not prevent it be closed – maybe someone succeeds. Anybody to give it a try?) But what can we do about other utilities?

Maybe we have to imitate a virus: attach the AHK script to an important Windows file, which cannot be killed without crippling Windows. This would also help against booting into safe mode and removing the script.

But what happens if Microsoft releases an update, which replaces the file? Anyone has an idea how to attach automatically back our script?
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sat Apr 30, 2005 3:45 am    Post subject: Reply with quote

Laszlo wrote:
Maybe we have to imitate a virus: attach the AHK script to an important Windows file, which cannot be killed without crippling Windows. This would also help against booting into safe mode and removing the script.
Shocked Sad
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Sat Apr 30, 2005 4:19 am    Post subject: Reply with quote

Just collecting ideas. Do you have any suggestions, which could work? If a user can remove the restrictions easily, why bother writing those tamper resistant SW.
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sat Apr 30, 2005 5:11 am    Post subject: Reply with quote

Laszlo wrote:
Just collecting ideas. Do you have any suggestions, which could work? If a user can remove the restrictions easily, why bother writing those tamper resistant SW.
My suggestion would be to securely connect a timer (like the type used to control outdoor lighting, etc...) to the PC power supply Wink...

Although I'm interested and would like to help I'm not sure I'd like to see a solution. Posting code for a script that cannot be stopped or disabled until a certain date, especially one that can't be stopped/modified by the person that wrote it doesn't sound like a great idea Sad. Although this request might have a valid reason there may be many other ears listening that don't...
Back to top
View user's profile Send private message Visit poster's website
sosaited



Joined: 24 Feb 2005
Posts: 233

PostPosted: Sat Apr 30, 2005 9:24 am    Post subject: Reply with quote

hi
thanks Laszlo
it works...(i just copy pasted it .. have to see what its doing:))
anyways..
the problem is that it keeps giving the message even if the time has been reversed (i did it manually..not through giving it a subroutine to change the time through cmd... and what about backup variables? :S (the Yday cant be used to set the month and the day of the month etc)...
anyways..i am going to read it it now..and see where to modify it (until then if u read this .. please reply)
thanks
(and we might not wanna go too far... but still i'll sendsome info onthis topic on how to make it (even securer) BUT AFTER 8th JUNE Smile )
*nothing is useless
and other than that i took it as a challenge (but u r right corrupt... cause u r not gonna find many psychos like me Exclamation )
Back to top
View user's profile Send private message Send e-mail MSN Messenger
sosaited



Joined: 24 Feb 2005
Posts: 233

PostPosted: Sat Apr 30, 2005 10:06 am    Post subject: Reply with quote

hey Laszlo
u used functions in ur script ? :S (actually i've never used them before.. and saw them for the first time in a script.. )
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Guest






PostPosted: Sat Apr 30, 2005 11:36 pm    Post subject: Reply with quote

Actually, the script can be simplified using AHK's time manipulations:
Code:
#persistent
Tick0 = %A_TickCount%
Time0 = %A_Now%

SetTimer TimeCheck, 1000
return

TimeCheck:
   Transform SecTick, Floor, (A_TickCount-Tick0)/1000
   SecPC = %A_Now%
   SecPC-= Time0,S

   if (SecTick-SecPC < 2 && SecPC-SecTick < 2)
      Return
   MsgBox PC time has been changed!
return
The "-=" (EnvSub) operator has an extra parameter, which makes AHK to calculate time differences. In this case in seconds ("S").
Back to top
Serenity



Joined: 07 Nov 2004
Posts: 1276

PostPosted: Sun May 01, 2005 12:05 am    Post subject: Reply with quote

You can disable the Task Manager via the registry, and its also possible to disable editing the registry too.
_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Sun May 01, 2005 1:01 am    Post subject: Reply with quote

(I was the last Guest with the simplifications, just forgot to log in.) I tried setting the date and time from an AHK script. I am stuck. Setting the date works perfectly with
Code:
run command.com /C date 04-30-2005
The same does not work with time
Code:
run command.com /C time 20:20:20
If you give the time in the wrong format you see a DOS box opened and a message, that the time is invalid. There you can enter any valid time, but nothing happens to the Windows system time. It looks like a secondary DOS environment is opened and the local time settings don’t affect the main system time. Does anyone know how to get around this?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group