Jump to content

ms conversion to days


Recommended Posts

ok, i am having trouble on this line

If Round(Int(TimerDiff($aTimer_Inits[1])) / 1000 * 60 * 60 * 24 * 5 , 2) >= $nTrial Then $nDays_Over += 5

i dont exactly understand how it works and what the numbers are for is because i need $nDays_Over variable to change to 5 when 5 days are up and i think it changes the variable when 5 MINUTES are up. any advice? help is needed :D

Link to comment
Share on other sites

Well, I think order of operations is applied (im not sure) so you might want to put that ti mind EDIT: never mind, it wouln't matter ,its all multiplication anyway, try doing it with those variables and just use a variable in your timer instead of all that confusing math

Edited by VindicatorOmega

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Link to comment
Share on other sites

First you need a static variable that defines the start date.

#Include <Date.au3>

$startDate = "2008/04/12 00:00:00"

If DateDiff('d', $startDate, _NowCalc()) > 5 Then MsgBox(0,"","5 day trial has ended")

Link to comment
Share on other sites

weaponx:

your method relys on the system clock so ppl could keep setting the time back and it wouldn't expire...

Hmm maybe i'm missing something. You are using TimerDiff() and i'm guessing TimerInit()? If this is the case all I have to do is reboot to run your script after the trial date. TimerInit() just stores the ticks since last boot.

Link to comment
Share on other sites

Hmm maybe i'm missing something. You are using TimerDiff() and i'm guessing TimerInit()? If this is the case all I have to do is reboot to run your script after the trial date. TimerInit() just stores the ticks since last boot.

no, its much more complex than that. ive rebooted several times and it still wont let me run it.

my point is that it expires too soon. i need it to expire after 5 days not 5 min

Link to comment
Share on other sites

no, its much more complex than that. ive rebooted several times and it still wont let me run it.

my point is that it expires too soon. i need it to expire after 5 days not 5 min

I find that hard to believe. Post more of your script. We don't know what $nTrial is, we don't know why you are incrementing $nDays_Over.

Link to comment
Share on other sites

What I've noticed for some GIF creator was that it noticed if your system time/date was earlier than when you last closed it.

So you could store the current time & date once at installation and then every time just before your script is stopped (encrypted in some .ini or something) and the next time your script is called, you can check whether a) it's been five days since installation or b ) the system time&date is too early; in both cases you'll tell the user that the trial has expired.

Working around that kind of protection is still possible, but it's a real nuisance for someone trying to use it past the trial time (I speak from experience :D)

Hope that helped.

Oh, and an idea: To make it real secure, store the time&date when the program is started and compare it to when it's closed, too; then the user can't confuse your program by setting the time back during the run.

Edited by WhiteAvenger
Link to comment
Share on other sites

any reliable methods?.....

You almost have to do something like this:

#include <GUIConstants.au3>

Const $trialKey = "HKLM\SOFTWARE\SuperSecretProgram"
Const $trialValue = "time"

;Number of days to allow
Const $timeLimit = 5

;Days converted to seconds
Const $runTime = $timeLimit * 24 * 60 * 60

;Start timer
$timer = TimerInit()

;Read in existing runtime
$totalTime = Int(RegRead($trialKey, $trialValue))
If @ERROR Then
    $totalTime = 0
EndIf

;Seconds remaining
$timeRemaining = $runTime - $totalTime

;Days remaining
$daysRemaining = StringFormat("%.2f",$timeRemaining / (24 * 60 * 60))

;If total runtime is greater than or equal to time limit (ex. 5 days = 432,000 seconds) exit program
If $totalTime >= $runTime Then
    MsgBox(0,"","Your " & $timeLimit & " day trial has ended")
    Exit
EndIf

GUICreate("Trial Program (" & $daysRemaining & " days remaining)")  ; will create a dialog box that when displayed is centered
GUISetState (@SW_SHOW)       ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ;Retrieve current runtime, add to existing runtime
            $totalTime += TimerDiff($timer)
            
            ;Store number of seconds program has been run
            RegWrite($trialKey,$trialValue,"REG_SZ",Int($totalTime/1000))
            ExitLoop
    EndSwitch
Wend

The only way to bypass this is for the end user to kill the program through the task manager or change the registry key containing the total running time. Unless they can decompile your script it should be safe.

Edited by weaponx
Link to comment
Share on other sites

dude this looks awesome, but how would killing the program bypass the trial protection?

The problem with his trial protection is that it converts the 5 days into runtime; so your trial doesn't expire after the 5th day of using it, but after 5 days of using it i.e. 5 days of runtime i.e. 120 hours or about 120 days if you use it one hour a day.

Killing the process will prevent the program from writing into the registry how much runtime has passed before stopping, so it thinks that this instance of using it hasn't happened and so won't count towards the 120 hours of allowed runtime.

Try the protection method I suggested:

#include <GUIConstants.au3>
#include <Date.au3>

Const $trialKey = "HKLM\SOFTWARE\SuperSecretProgram"

; Number of days to allow
Const $timeLimit = 5

; Check for key if program is expired; if key does not exist, set to false
RegRead($trialKey,"expired")
If @ERROR Then
    RegWrite($trialKey,"expired","REG_BINARY",StringToBinary(_BooleanToString(false)))
EndIf
; Retrieve whether program is expired; if yes, exit
$expired = _StringToBoolean(BinaryToString("0x"&RegRead($trialKey,"expired")))
If $expired Then
    MsgBox(0,"Error","Your trial period has expired.")
    Exit
EndIf

; Check if registry key for first run exists; if not, create it with current date and time
RegRead($trialKey,"firstRun")
If @ERROR Then
    RegWrite($trialKey,"firstRun","REG_BINARY",StringToBinary(_NowCalc()))
EndIf

; Retrieve first run time
$firstRun = BinaryToString("0x"&RegRead($trialKey,"firstRun"))
; Compare first run time with current time & date; if negative (i.e. current date is earlier than first run), exit
$timeDiff = _DateDiff('s',$firstRun,_NowCalc())
If $timeDiff < 0 Then
    RegWrite($trialKey,"expired","REG_BINARY",StringToBinary(_BooleanToString(true)))
    MsgBox(0,"Error","The current time is earlier than the install time.")
    Exit
EndIf
; Calculate number of days the program hs been used; if >= the time limit, exit
$daysUsed = _DateDiff('d',$firstRun,_NowCalc())
If $daysUsed >= $timeLimit Then
    RegWrite($trialKey,"expired","REG_BINARY",StringToBinary(_BooleanToString(true)))
    MsgBox(0,"Error","Your trial period has expired.")
    Exit
EndIf

; Calculate how many days remain for the trial
$daysRemaining = $timeLimit - $daysUsed

; Check if registry key for last run exists; if not, create it with current date and time
RegRead($trialKey,"lastRun")
If @ERROR Then
    RegWrite($trialKey,"lastRun","REG_BINARY",StringToBinary(_NowCalc()))
EndIf

; Compare last run time with current time; if negative (i.e. current time is earlier than last run time), exit
$lastRun = BinaryToString("0x"&RegRead($trialKey,"lastRun"))
$timeDiff = _DateDiff('s',$lastRun,_NowCalc())
If $timeDiff < 0 Then
    RegWrite($trialKey,"expired","REG_BINARY",StringToBinary(_BooleanToString(true)))
    MsgBox(0,"Error","The current time is earlier than the last run time.")
    Exit
EndIf

GUICreate("Trial Program (" & $daysRemaining & " days remaining)")  ; will create a dialog box that when displayed is centered
GUISetState (@SW_SHOW)       ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ; When GUI is closed, retrieve last run time and compare with current time
            $lastRun = BinaryToString("0x"&RegRead($trialKey,"lastRun"))
            $timeDiff = _DateDiff('s',$lastRun,_NowCalc())
            ; If current time is earlier than last run time (i.e. time has been turned back), set trial as expired and exit
            If $timeDiff < 0 Then
                RegWrite($trialKey,"expired","REG_BINARY",StringToBinary(_BooleanToString(true)))
                MsgBox(0,"Error","The current time has been turned back during run time.")
                Exit
            EndIf
            ; Store current time as last RunTime
            RegWrite($trialKey,"lastRun","REG_BINARY",StringToBinary(_NowCalc()))
            ExitLoop
    EndSwitch
Wend

Func _StringToBoolean ( $strVal )
    If $strVal = "False" Then
        Return False
    Else
        Return True
    EndIf
EndFunc

Func _BooleanToString ( $boolVal )
    If $boolVal Then
        Return "True"
    Else
        Return "False"
    EndIf
EndFunc

The only way to bypass that is to delete the registry keys; I haven't found a way around doing that yet, but perhaps someone can suggest something.

I have "encrypted" all the values by writing them into the registry as binary, so it's not too easy to change the values.

Try this method and see if it works for you.

EDIT: There was an error with the binary values; it's now fixed.

Edited by WhiteAvenger
Link to comment
Share on other sites

Ok, it works great. So the ONLY way they can have an unlimited use is if they delete the registry keys?

Yup... And even then they'd have to re-delete them every 5 days.

And if you have an installer for your script, you can create the registry keys once and then make sure that when they're not there, that means that the trial has expired - which would work around the deleting the key trick.

I'm just working on a keyfile system for added security, but I'm not sure whether it's actually useful. I'll see tomorrow...

Edited by WhiteAvenger
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...