Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

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
0
Daron1
Asked:
Daron1
  • 6
  • 4
  • 2
1 Solution
 
wsh2Commented:
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

0
 
ArkCommented:
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
0
 
ArkCommented:
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
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
wsh2Commented:
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 ----->
0
 
ArkCommented:
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
0
 
ArkCommented:
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
0
 
wsh2Commented:
Sorry for going offthread Daron1.. but Ark, I think you got the Riddle.. Well Done!!!.. You should propose it..  <smile>.
0
 
wsh2Commented:
Ark:
Just tested it.. <sigh>.. didn't work in the English character set.. but GREAT idea !!!
0
 
Daron1Author Commented:
Edited text of question.
0
 
wsh2Commented:
Hi Daron1.. <smile>

Ark and I pointed some ways a program (or your program for that matter) could store a Date for testing. Exactly how and where this date is being stored, is going to take come detective work / reverse engineering.

The obvious place to start is with the class module that created the .LastRunDate property. As you indicated in your question, your application is wrapped by a Shareware package. If so, what is the name of it / website URL.. and how is it implemented into your program? If it is a simple Date checker, it probably will not be too hard to crack. However, if the software is done by someone good (ie. loaded with encryption and/or dynamic data recursions.. etc), it could take months to figure out.. <sigh>.

As such, to go any further, you will have to provide more information.. <smile>
0
 
Daron1Author Commented:
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
0
 
wsh2Commented:
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>.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now