Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read year month day from registry 1

Status
Not open for further replies.

Stougaards

Technical User
Nov 18, 2011
10
DK
Hey There.
I have a VB script which reading AV signatur date information from registry and compare the day with today,
and gives the difference in days, but when reading this 2011/11/17 from a registry key im getting Microsoft VBScript runtime error:
Type mismatch: 'CDATE'

This is the definition in the VB script.

oYear = Left(oDate,4)
oMonth = Mid(oDate,5,2)
oDay = Right(oDate,2)
oNDate = CDATE(oYear &"/"& oMonth &"/"& oDay)


If I remove the / from 2011/11/17 in registry, it works fine.
What am I doing wrong ?
I can post more of the script if requested. Don't know if this is allowed :)

Thanks.
Stougaards (newbee to tek-tips)
 
Have you tried this ?
oNDate = CDate(oDate)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
What is the output of the following code ?
Code:
WScript.Echo "'" & oDate & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
So, how is oDate supposed to get a value ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Found the Code way,I'm new to this. :)
I know it long, but it the full script.

It reads the data in the registry, and makes a file.
Dont know if it any help to solve the problem, but I hope so.


Credit goes to where credit is to be...


Code:
Option Explicit
'Script to be used with BBNT to check Symantec Corp Ed virus definition version
'Jeff Ehrenberg jeff @ uscomputerconnection.com
'
'Script to be used with BBWin to check Mcafee Antivirus definition version, Symantec pillet ud af.
' SAV output file ændret til sigav
'Tilrettet af Kenneth S. Petersen Nov. 2011
'
'
' Modified 16/08/06 to work with Austrailian date format Graeme Shea Graeme@shea.com.au
' Modified 18/08/06 to work to allow for using liveupdate. Live update stores
' now allows for 64 bit machines.
' virus def information in different key. Graeme Shea Graeme@shea.com.au
' 0.9. Added debug logging and version no.  Graeme Shea 06/09/06
' 1.0 Added search for BBWin path and current time to output file.  Graeme Shea 17/12/07

Const Version = "1.0"
Const bCreateLog = false		'If true adds debugging info to output file.
Const ForReading = 1 
Const ForWriting = 2 
Const ForAppending = 8
Dim oShell,oDef,oDef2,oDate,oDate2,oVer,oVer2,oRev,oOutFile,oFSO
Dim oNDate,oToday,oYear,oMonth, oDay, oHour2, oMinute2, oSecond2, oDateDiff, oRev2, oYear2, oMonth2, oDay2, oNDate2, b64Bit, szLog, ExtPath

Set oFSO= CreateObject("Scripting.FileSystemObject")
Set oShell = WScript.CreateObject("WScript.Shell")

If bCreateLog Then WriteLog("Debug logging enabled. ")

' Find path for extenal files
On Error Resume Next
ExtPath = oShell.RegRead("HKLM\SOFTWARE\bbwin\ExtPath\")
If IsEmpty(ExtPath) Then
	ExtPath = oShell.RegRead("HKLM\SOFTWARE\BBWin\tmppath")
End If
If Not IsEmpty (ExtPath) Then  'If not empty then we have 32bit machine
	b64Bit = False
End If
If IsEmpty(ExtPath) Then
	ExtPath = oShell.RegRead("HKLM\SOFTWARE\Wow6432node\bbwin\ExtPath\")
End If
If IsEmpty(ExtPath) Then
	ExtPath = oShell.RegRead("HKLM\SOFTWARE\Wow6432node\BBWin\tmppath")
End If

If Not IsEmpty(ExtPath) And isEmpty(b64Bit) Then 
	b64Bit = True
	err.clear
	If bCreateLog Then WriteLog("64bit System Detected. ")
End If

If Not IsEmpty(ExtPath) Then
	If bCreateLog Then WriteLog("Got External Path as " & ExtPath)
Else 
	Call WriteLog("Fatal Error External Path Not Found!")
End If
on Error GoTo 0

Set oOutFile = oFSO.CreateTextFile (ExtPath & "\sigav")

If bCreateLog Then WriteLog("Created Output file " & ExtPath & "\sigav")
oToday = FormatDateTime(Now, vbShortDate)
'Check Virus Def Date by reading value from registry

If bCreateLog Then WriteLog("Got todays date as " & oToday)
if not b64Bit then
	oDef = oShell.RegRead ("HKLM\SOFTWARE\McAfee\AVEngine\AVDatDate")
	Else 
	oDef = oShell.RegRead ("HKLM\SOFTWARE\Wow6432Node\McAfee\AVEngine\AVDatDate")
end If
If bCreateLog Then WriteLog("Got McAfee Auto update Def date as " & oDef)


oVer = Right(oDef,12)
oRev = Right(oVer,3)
oDate = Left(oVer,8)

oYear = Left(oDate,4)
oMonth = Mid(oDate,5,2)
oDay = Right(oDate,2)

'oNDate = CDATE(oMonth &"/"& oDay &"/"& oYear) 		'American Date format
'oNDate = CDATE(oDay &"/"& oMonth &"/"& oYear)  	'Australian Date Format
[b]It this line that fails[/b]
oNDate = CDATE(oYear &"/"& oMonth &"/"& oDay)   	'Mcafee Date format

'Determine age of virus definitions, if more then 7 days old display yellow on BB
If bCreateLog Then WriteLog("Converted McAfee Auto Update Def to " & oNDate)
oDateDiff = DateDiff("d", oNDate, oToday)
If bCreateLog Then WriteLog("Got Date Difference as " & oDateDiff)
' If you do a live update def date is stored if diff key so also try other key.

if not b64Bit then
	oDef2 = oShell.RegRead ("HKLM\SOFTWARE\Network Associates\ePolicy Orchestrator\Application Plugins\VIRUSCAN8600\DatDate")
	Else 
	oDef2 = oShell.RegRead ("HKLM\SOFTWARE\Wow6432Node\Network Associates\ePolicy Orchestrator\Application Plugins\VIRUSCAN8600\DatDate")
end if

If bCreateLog Then WriteLog("Got McAfee Auto update Def date as " & oDef2)

oVer2 = Right(oDef2,12)
oRev2 = Right(oVer2,3)
oDate2 = Left(oVer2,8)


oDay2 = Left(oDate2,2)
oMonth2 = Mid(oDate2,5,2)
oYear2 = Right(oDate2,4)

'oNDate2 = CDATE(oMonth2 &"/"& oDay2 &"/"& oYear2) 	'American Date format
'oNDate2 = CDATE(oDay2 &"/"& oMonth2 &"/"& oYear2)	'Austrailan Date Format
oNDate2 = CDATE(oYear &"/"& oMonth &"/"& oDay)   	'Mcafee Date format

If bCreateLog Then WriteLog("Converted McAfee Auto Update Def to " & oNDate2)
If bCreateLog Then WriteLog("Got Date Difference as " & DateDiff("d", oNDate2, oToday))

' find which def date is newer and write results to Big Brother file.
if oDateDiff>DateDiff("d", oNDate2, oToday) Then
	If bCreateLog Then WriteLog("Using McAfee Auto udate Def date. ")
      oDateDiff = DateDiff("d", oNDate2, oToday)

'If (oDateDiff > 8) Then = High nr. equal High count of days.
      If (oDateDiff > 8) Then

	oOutFile.WriteLine "yellow+12h   Test run at " & Now
        Else oOutFile.WriteLine "green+12h   Test run at " & Now
      End If
      oOutFile.WriteLine vbCrLf &"Found McAfee Enterprise Anti Virus definition file version:"
      oOutFile.WriteLine oNDate2 &" Rev. "& oRev2
      oOutFile.WriteLine "Virus definitions are "& oDateDiff &" day(s) old"
      
Else

	If bCreateLog Then WriteLog("Using McAfee Auto update Def date. ")
      If (oDateDiff > 8) then
	oOutFile.WriteLine "yellow+12h   Test run at " & Now
        Else oOutFile.WriteLine "green+12h   Test run at " & Now
      End If
      oOutFile.WriteLine vbCrLf &"Found McAfee Enterprise Anti Virus definition file version:"
      oOutFile.WriteLine oNDate &" Rev. "& oRev
      oOutFile.WriteLine "Virus definitions are "& oDateDiff &" day(s) old"
end If
oOutFile.WriteLine "Check completed at "& Time
oOutFile.WriteBlankLines(3)
oOutFile.WriteLine "McAfee AV, McAv.vbs Version " & Version

oOutFile.WriteBlankLines(3)
oOutFile.WriteLine szLog
oOutFile.Close 

Sub WriteLog(szText)

	'Set oLogFile = oFSO.OpenTextFile (ExtPath &"\sigav.log", ForAppending,True)
	'oLogFile.WriteLine (szText & "   Current time is " & time)
	'oLogFile.Close
	szLog = szLog & szText & VbCrLf
End Sub

Stougaards
 
One more thing.
In registry it says 2011/11/17
year month day with the /

When I remove the / from registry the script works.

Thanks for all the help so fare.
Stougaards.
 
In registry it says 2011/11/17
Which key ?

Anyway, what is the value of oDef ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
oDef is the output from this key.
oDef = oShell.RegRead ("HKLM\SOFTWARE\McAfee\AVEngine\AVDatDate")
which is 2011/11/18 equals today.

if your using Mcafee AV.
But you can make it read any key in registry, which holds the date format like year/month/day.
it works fine, but when slash / is in the format, the script fails.
There must be something i'm missing.

// Stougaards
 
which is 2011/11/18
So, why not simply this ?
oNDate = CDate(oDef)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I would if it will work.

The problem is that symantec writes 20111118
year month day, but mcafee writes 2011/11/18
year/month/day, and the varibels works in the script.
It's the / that is the main problem in registry.
If it's removed from registry, the script works, but can't make mcafee write the signatur install date without the /.

How to read year month day from registry, when one key is with / and another key is without the /

hope the clearfies something.
// Stougaards.


 
It works PHV.

I'm a happy man.
Thx.
Credit goes to.... YOU.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top