Link to home
Start Free TrialLog in
Avatar of Jeffrey Renfroe
Jeffrey RenfroeFlag for United States of America

asked on

Problems checking date for registry key using vbs

Hello. I am trying to get the below script to check the date. If the date is less than one day old, it will display my message box and quit. If the date is older than 1 day, it will display another message box I have.

I assume my problem is in the way I am checking the date. I am modifying an existing script that I have.

The date is in the format of 4/15/2009 - 16:08:04. I am not concerned about the time. I only want it to check the date. Currently, the script always displays the installing message box.

Any help would be appreciated.
DateCheck
 
Function DateCheck
 
Dim objShell
Dim strComputer
Dim objRegistry
Dim strKeyPath
Dim strValueName
Dim strValue
Dim intReturn
Dim arrDateBits
Dim dteDate
 
 
 
Set objShell = CreateObject("WScript.Shell")
Const HKLM = &H80000002
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = """SOFTWARE\Packages\FTC\FTC Base Package"""
strValueName = "InstallDate"
intReturn = objRegistry.GetStringValue(HKLM, strKeyPath, strValueName, strValue)
If intReturn = 0 Then
	If InStr(strValue, "-") > 0 Then
		arrDateBits = Split(strValue, "/")
		If UBound(arrDateBits) = 2 Then
			dteDate = CDate(arrDateBits(0) & "/" & MonthName(arrDateBits(1), True) & "/" & arrDateBits(2))
			If dteDate < DateAdd("d", -1, Now) Then
			MsgBox "Exit"
			WScript.Quit
			End If
		Else
		End If
	Else
	End If
Else
MsgBox "Installing"
End If
 
Set objShell = Nothing
Set objRegistry = Nothing
 
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TakedaT
TakedaT
Flag of United States of America image

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 Jeffrey Renfroe

ASKER

This is great. Thank you for the help.