Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problems checking date for registry key using vbs

Posted on 2009-04-15
2
Medium Priority
?
185 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:Lorrec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
TakedaT earned 2000 total points
ID: 24151206
Try this code.  I think that all the extra quotes around the reg path in line 21 caused your getstring to return an error.

Since you are not worried about the time, I had the time stipped off of arrDateBits(2) in line 29.  I entered a date just as you specified and it works for me.

If you want the time included, it shouldnt be to difficult.
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) & "/" & arrDateBits(1) & "/" & left(arrDateBits(2),4))
			If dteDate < DateAdd("d", -1, Now) Then
				MsgBox "Older than a day Exit"
				WScript.Quit
			Else
				MsgBox "Newer than a day 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

0
 

Author Closing Comment

by:Lorrec
ID: 31570556
This is great. Thank you for the help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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