Solved

reset date

Posted on 2000-04-02
12
269 Views
Last Modified: 2010-05-02
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
Comment
Question by:Daron1
  • 6
  • 4
  • 2
12 Comments
 
LVL 14

Expert Comment

by:wsh2
ID: 2678750
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
 
LVL 27

Expert Comment

by:Ark
ID: 2678794
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
 
LVL 27

Expert Comment

by:Ark
ID: 2678835
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2678877
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
 
LVL 27

Expert Comment

by:Ark
ID: 2678889
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
 
LVL 27

Expert Comment

by:Ark
ID: 2678920
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 14

Expert Comment

by:wsh2
ID: 2678940
Sorry for going offthread Daron1.. but Ark, I think you got the Riddle.. Well Done!!!.. You should propose it..  <smile>.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2678951
Ark:
Just tested it.. <sigh>.. didn't work in the English character set.. but GREAT idea !!!
0
 

Author Comment

by:Daron1
ID: 2680085
Edited text of question.
0
 
LVL 14

Accepted Solution

by:
wsh2 earned 100 total points
ID: 2682407
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
 

Author Comment

by:Daron1
ID: 2682428
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2682480
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now