Hi there.
I have a countdown timer that counts from 2 hours down to 0. when it gets to 0 it logs the user of. Now i have got all this fully working.
the problem i am having is restoring the time. the application stores the date of the when the applcation is run (at startup) in the registry. and at the moment i can get the current time left on the timer stored in the reg every second . so for example
The application is running fine , then it just crashes (for some reason) but the user only had 54 minutes remaining (0:54:00). When the application restarts , instead of going back to 2 hours , it should resume from the 54 minutes. or instead of crashing the user logs out and then logs back in (on the same date) it should resume from 54 minutes.
Hope this makes sense.
Here is the code i am using.
The problem part i have bolded and underlined. this is the part that i am having trouble with, is just getting the time from reg and resuming the timer with this time , hope this makes sense.
Thanks
Alex
I have a countdown timer that counts from 2 hours down to 0. when it gets to 0 it logs the user of. Now i have got all this fully working.
the problem i am having is restoring the time. the application stores the date of the when the applcation is run (at startup) in the registry. and at the moment i can get the current time left on the timer stored in the reg every second . so for example
The application is running fine , then it just crashes (for some reason) but the user only had 54 minutes remaining (0:54:00). When the application restarts , instead of going back to 2 hours , it should resume from the 54 minutes. or instead of crashing the user logs out and then logs back in (on the same date) it should resume from 54 minutes.
Hope this makes sense.
Here is the code i am using.
VB.NET:
[U]Timer1[/U]
Dim valueToWrite4 As String = lblTimeLeft.Text
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\TA\", "LOGINTIMELEFT", valueToWrite4)
Dim remainingTime As TimeSpan = Me.endTime.Subtract(Date.Now)
Dim LLT As DateTime
Dim HReg1 As Object
HReg1 = CreateObject("Wscript.shell")
LLT = HReg1.RegRead("HKEY_CURRENT_USER\Software\TA\LOGINTIMELEFT")
Me.lblTimeLeft.Text = String.Format("{0}:{1:d2}:{2:d2}", remainingTime.Hours, remainingTime.Minutes, remainingTime.Seconds)
VB.NET:
[U]Form Load[/U]
If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\TA\", _
"LASTLOGINDATE", Nothing) Is Nothing Then
Dim valueToWrite1 As String = "19/07/2009"
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\TA\", "LASTLOGINDATE", valueToWrite1)
End If
Dim LLD As Date
Dim HReg As Object
Dim LLT As DateTime
Dim HReg1 As Object
HReg = CreateObject("Wscript.shell")
LLD = HReg.RegRead("HKEY_CURRENT_USER\Software\TA\LASTLOGINDATE")
HReg1 = CreateObject("Wscript.shell")
LLT = HReg.RegRead("HKEY_CURRENT_USER\Software\TA\LOGINTIMELEFT")
If LLD.Date.CompareTo(Date.Now.Date) = 0 And LLT = "0:00:00" Then
Dim Result1 As Integer
Result1 = MessageBox.Show("You Have Used All 2 Hours Of Your Time" + Environment.NewLine + "For Date:" & " " & LLD, "Time Limit", MessageBoxButtons.OK, MessageBoxIcon.Warning)
If vbOK Then
Process.Start("C:\Windows\System32\logoff.exe")
Me.Close()
Me.Dispose()
End If
Else
Me.Left = Screen.PrimaryScreen.WorkingArea.Width - Me.Width - 20
Me.Top = Screen.PrimaryScreen.WorkingArea.Height - Me.Height - 50
[B][U]If LLD.Date.CompareTo(Date.Now.Date) = 0 And Not LLT = "0:00:00" Then
Dim LTT1 As DateTime = LLT
lblTimeLeft.Text = LTT1
Me.endTime = LLT1
Me.Timer1.Start()
Else[/U][/B] Me.lblTimeLeft.Text = "2:00:00"
Me.endTime = Date.Now.AddHours(2)
Me.Timer1.Start()
Me.Timer2.Start()
Dim Result As Integer
Result = MessageBox.Show("You have a 2 Hour Time Limit For Date: " & " " & Date.Now.ToShortDateString + Environment.NewLine + "This Lasts For 24 Hours Only & Must be used in one session" + Environment.NewLine + "If You Agree And Want To Continue Press
Yes.", "Time Limit Agreement", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
If Result = vbNo Then
Process.Start("C:\Windows\System32\logoff.exe")
Me.Close()
Me.Dispose()
End If
End If
End If
The problem part i have bolded and underlined. this is the part that i am having trouble with, is just getting the time from reg and resuming the timer with this time , hope this makes sense.
Thanks
Alex
Last edited: