#125781 - 2004-08-30 12:49 PM
Re: Get the date a file was last accessed
|
Cybex
Getting the hang of it
   
Registered: 2004-07-21
Posts: 81
Loc: Brandon, FL.
|
TRUE that, for sorting. I just realized I do use that date format for my log files. I tried to wrap your code into an app to run against remote computers listed in an ini file and look for apps listed in the same ini file. But I think the way you scripted your originally will not work against remote computers. Please take a look at my poorly written code and see if this is the case or just reconfirm I don't have a clue. P.S. Sorry, I killed EXPLICIT for testing.
Break On Dim $SO, $inifile $SO=SetOption('Explicit','OFF')
; Absolute path for the INI file $inifile = "K:\Kix Scripts\Kix\test.ini"
ENUMCOMPUTERS($inifile, "Computers")
Function CHECKAGE($CompName, $AppName) Dim $HKLMAppPaths,$sFile,$LADate,$TimeDiff $HKLMAppPaths=$CompName +'\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths' $sFile=Trim(ReadValue($HKLMAppPaths + '\' + $AppName,'')) $LADate=Split(Trim(Join(Split(fnGetFileProp($sFile,DateLastAccessed),""),"",1)),"/") $LADate=$LADate[2]+"/"+Right("0"+$LADate[0],2)+"/"+Right("0"+$LADate[1],2) $TimeDiff=DateCalc(@DATE,$LADate) If $TimeDiff => 2 ; change to date you want to test MessageBox('The file ' + $sFile + ' has not been accessed in over ' + $TimeDiff + ' days.','Test',,) MessageBox('The file ' + $sFile + ' Last Accessed: ' + $LADate + Right(fnGetFileProp($sFile,DateLastAccessed),-10), 'Test',,) EndIf EndFunction Function fnGetFileProp($sFile,$sProp) Dim $objFSO, $objFile, $nul $objFSO = CreateObject("Scripting.FileSystemObject") If NOT VarType($objFSO)=9 Exit 1 EndIf $objFile = $objFSO.GetFile($sFile) If NOT VarType($objFile)=9 Exit 2 EndIf $nul=Execute("$$fnGetFileProp = $$objFile."+$sProp) If VarType($fnGetFileProp)=0 Exit 87 EndIf EndFunction Function DateCalc($date1, $DateOrMod, optional $SingleDigit) Dim $_intDate1, $_intYear1, $_intMonth1, $_intDay1 Dim $_intDate2, $_intYear2, $_intMonth2, $_intDay2 $date1 = Split($date1,'/') If Ubound($date1) <> 2 Exit 1 EndIf $_intYear1 = Val($date1[0]) $_intMonth1 = Val($date1[1]) $_intDay1 = Val($date1[2]) If $_intMonth1 < 3 $_intMonth1 = $_intMonth1 + 12 $_intYear1 = $_intYear1 - 1 EndIf $_intDate1 = $_intDay1 + ( 153 * $_intMonth1 - 457 ) / 5 + 365 * $_intYear1 + $_intYear1 / 4 - $_intYear1 / 100 + $_intYear1 / 400 - 306 Select Case VarType($DateOrMod) = 3 $_intDate2 = $_intDate1 + $DateOrMod If InStr($_intDate2,'-') $_intDate2 = Val(SubStr($_intDate2,2,Len($_intDate2)-1)) EndIf $_intYear2 = ( 100 * ( ( ( 100*($_intDate2+306)-25)/3652425) - ( ((100*($_intDate2+306)-25)/3652425)/4) ) + (100*($_intDate2+306)-25) ) / 36525 $_intMonth2 = ( 5 * ( ( ( 100*($_intDate2+306)-25)/3652425) - ( ((100*($_intDate2+306)-25)/3652425)/4) + ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4 ) + 456 ) / 153 $_intDay2 = ( ( ( 100*($_intDate2+306)-25)/3652425) - ( ((100*($_intDate2+306)-25)/3652425)/4) + ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4 ) - ( 153 * $_intMonth2 - 457 ) / 5 If $_intMonth2 > 12 $_intYear2 = $_intYear2 + 1 $_intMonth2 = $_intMonth2 - 12 EndIf If NOT $SingleDigit If Len($_intYear2 ) < 4 $_ = Execute("for $i=1 to 4-len($$_intYear2) $$_intYear2 = '0' + $$_intYear2 next") EndIf $_intMonth2 = Right("0" + $_intMonth2,2) $_intDay2 = Right("0" + $_intDay2,2) EndIf $DateCalc = '$_intYear2/$_intMonth2/$_intDay2' Case VarType($DateOrMod) = 8 $DateOrMod = Split($DateOrMod,'/') If Ubound($DateOrMod) <> 2 Exit 1 EndIf $_intYear2 = Val($DateOrMod[0]) $_intMonth2 = Val($DateOrMod[1]) $_intDay2 = Val($DateOrMod[2]) If $_intMonth2 < 3 $_intMonth2 = $_intMonth2 + 12 $_intYear2 = $_intYear2 - 1 EndIf $_intDate2 = $_intDay2 + ( 153 * $_intMonth2 - 457 ) / 5 + 365 * $_intYear2 + $_intYear2 / 4 - $_intYear2 / 100 + $_intYear2 / 400 - 306 $DateCalc = $_intDate1 - $_intDate2 ;comment the next line if you wish to return negative results also !!! If InStr($DateCalc,'-') $DateCalc = Val(SubStr($DateCalc,2,Len($DateCalc)-1)) EndIf Case 1 Exit 1 EndSelect EndFunction
Function ENUMCOMPUTERS($fl,$sectionentry) Dim $CompKeys,$CompName $CompKeys=Split(ReadProfileString($fl,$sectionentry,''),Chr(10)) For Each $CompName In $CompKeys If $CompName <>'' MessageBox($CompName, "Computer",,) ENUMAPPS($fl, "Apps", $CompName) EndIf EndFunction
Function ENUMAPPS($fl, $sectionentry, $CompName) Dim $AppKeys,$AppName $AppKeys=Split(ReadProfileString($fl,$sectionentry,''),Chr(10)) For Each $AppName In $AppKeys ; MessageBox("hi","hi",,) If $AppName <>'' MessageBox($AppName, "Computer and App",,) CHECKAGE($CompName, $AppName) EndIf EndFunction
_________________________
Common sense isn't so common.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|