Link to home
Start Free TrialLog in
Avatar of Daron1
Daron1

asked on

reset date

I am very impressed with the responses that have been given.  I would like to make a point more clear however.  I am successfully getting the lastdaterun (which gives the error message).  Where I am now Is I get the error message(changed date).  I can't remove the fact I changed the date.  As it is now I can't view the register window because it will not do anything but give this date error.  I want to do some action that will allow a new "initial" date to be given so I can start the program fresh.  I hope this makes it more clear.

I have a VB program that I've wrapped with a shareware package for allowing the program to be run for so many days.  It also checks if the user has moved the date backwards.  I was checking this feature (which by the way works great) and now I can't get the thing to work properly.  I need somehow to reset the .LastDateRun property(I think).  Here is a snippit that checks this.:

 If .LastRunDate > Now Then
         MsgBox "You've changed the clock backwards!"
         Unload MainForm
         Exit Sub
      End If

I have to present my program soon and I don't want to remove this feature.  thanks.

Daron
Avatar of wsh2
wsh2

What data type is .LastRunDate?

If it is a Date data type, then the code will work. If it is a string data type, you have to convert it to do your comparison.

If Cdate(.LastRunDate) > Now Then
   MsgBox "You've changed the clock backwards!"
   Unload MainForm
   Exit Sub
End If

Avatar of Ark
Hi
You can do it by two ways.
1. Saving some dummy file (if your app don't save its own) and everytime you start your app compare this file date with current date.
2. Save current date into registry and compare it when start.

Code:
First way:
Private Sub FormMain_Load()
  Dim sFile As String, nFile As Integer
  nFile = FreeFile
  sFile = "c:\windows\system\dummy.dll"
  If Dir$(sFile) = "" Then
     Open sFile For Output As #nFile
     Close #nFile
  End If
  If FileDateTime(sFile) > Now Then
     MsgBox "You've changed the clock backwards!"
     Unload MainForm
     End
  Else
     Open sFile For Output As #nFile
     Close #nFile
  End If
End Sub

Cheers
Second way:
Start new project, add reference (VB menu -> Project -> References...-> Windows Scripting Host Object Model (WSHOM.OCX))
Private Sub Form_Load()
  Dim wshShell As New IWshShell_Class
  Dim s As String, sReg As String
  On Error Resume Next
  sReg = "HKCU\Software\MyApp\LastDateRun"
  s = wshShell.RegRead(sReg)
  If Err Then
     s = CStr(Now)
     wshShell.RegWrite sReg, s
  End If
  On Error GoTo 0
  If CDate(s) > Now Then
     MsgBox "You've changed the clock backwards!"
     Unload MainForm
     End
  Else
     wshShell.RegWrite sReg, CStr(Now)
  End If
End Sub

Cheers
Ark:
Shame on you for putting that file into the Windows\System directory.. <mother speaking now>.. "now go right upstairs and cleanup your bedroom".. (just kidding.. <smile> and a <wink>).  The Windows\System directory is a mess to begin with. Who knows that someone else didn't already place a Dummy.Dll file (with functionality) there. Additionally, if the application is uninstalled properly, you are left with a dangling DLL just taking up space. For Dummy files, I think writing them to a Hidden directory under the App.Directory with their hidden and Readonly attributes set.. keeps things neat.. <smile>. But then again, I am old and anal.. <lol>.
--------------------------------------
If he wants to do this on his own, the best place to do it is the Registry. Actually, it is not hard thing to do using the GetSetting and SaveSetting VB functions.

<----- Code Begin ----->

' Setup / Test Expiration Date
If GetSetting(App.Title, "Dates", "RunDateExpire", "AddNew") = "AddNew" _
Then
   Call SaveSetting(App.Title, "Dates", "RunDateExpire", Format(Now + Day(30)))
Else
   If Now > CDate(GetSetting(App.Title, "Dates", "RunDateExpire")) _
   Then
      MsgBox ("Application Has Expired")
      Exit Sub
   End If
End If

' Setup / Test Last Run Date
If GetSetting(App.Title, "Dates", "RunDateLast", "AddNew") = "AddNew" _
Then
   Call SaveSetting(App.Title, "Dates", "RunDateLast", Format(Now))
Else
   If Now < CDate(GetSetting(App.Title, "Dates", "RunDateLast")) _
   Then
      MsgBox ("Application Has Lastd")
      Exit Sub
   Else
      Call SaveSetting(App.Title, "Dates", "RunDateLast", Format(Now))
   End If
End If

<----- Code End ----->
Hello wsh2,
<What data type is .LastRunDate? > - may be it's your favorite FSO? :-)
'But this code doesn't work - Last access change when app start
'---------- Don't work, only for sample
  Dim FSO As New FileSystemObject
  Dim MyFile As File
  Dim s As String
  s = App.Path
  If Right$(s, 1) <> "\" Then s = s & "\"
  s = s & App.EXEName & ".exe"
  Set MyFile = FSO.GetFile(s)
  Caption = MyFile.DateLastAccessed
  If MyFile.DateLastAccessed > Now Then
     End
  End If
'--------
Cheers
wsh2,
OK, I'll never offer somebodyd to write something in windows\system directory (In above sample I was only sure that Daron has this directory - don't know about others). If I want to hide some file, I make this trick - do you see second letter in file name - kårnel32.dll? In russian second and fifth chars are the same. BTW, simple way to solfe ameba's puzzle
Caption
Càption - both statement looks same on my machine, but second gives error. But this is not a solution. First time I make function at Bus Module:
Public Function MsgBox(s As String, i As Integer) As Integer
    If s = "Hello" Then MsgBox = i Else Err.Raise 1, , "Hehe is not allow"
End Function
and this does a trick, now I'm looking for controls which have default property/method with (string,integer) parameters
Cheers
Sorry for going offthread Daron1.. but Ark, I think you got the Riddle.. Well Done!!!.. You should propose it..  <smile>.
Ark:
Just tested it.. <sigh>.. didn't work in the English character set.. but GREAT idea !!!
Avatar of Daron1

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of wsh2
wsh2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daron1

ASKER

I have to agree with you wsh2.  I have found that the .LastRunDate is encrypted in the registry.  The shareware portion of the VB is implemented thru an activeX component added to the VBP.  I did find, however that by renaming the software name within this activeX component, the date was reset.  The way this is implemented well and thus prevents the user from changing the date. (BTY, my intention with the time limit is strictly to allow me to update the users with changes as they are needed, and not to limit user access.)  The software I downloaded for this is good and if you have a use for it let me know and I'll pass the info along.  I'm a dpf3@ra.msstate.edu

Daron
Hmmmm.. when and if you have the time (and energy) then you may just want to try deleting the registry key.. and see what happens. As you may have noted in the Registry code above, a good programmer will initialize the key value before using it. Perhaps, in the initialization process, the wrapper will accord the user another 30 days.. <wink>.

Also, if you have a Hex Editor.. you may want to look at the OCX's binary code. In it, look for registry thype strings beginning with HKEY, to see if it may be posting elsewhere.

Anyhow.. Thank YOU for the points.. and good luck in your endeavor.. <smile>.